Page 6 of 9
Re: sock.lua - A simple networking library for LÖVE
Posted: Fri Jun 16, 2017 7:09 pm
by Ikroth
Sir_Silver wrote: ↑Fri Jun 16, 2017 4:54 am
Yes, the minimum amount of code needed to cause the error is this:
Code: Select all
local sock = require("lib/networking/sock")
local server = sock.newServer(my_ip_here, 27015)
where my_ip_here is a string that is my public ip address.
What operating system are you running? Did you try running as administrator/root?
Re: sock.lua - A simple networking library for LÖVE
Posted: Wed Jun 21, 2017 3:24 am
by yetneverdone
It would be awesome if you could provide a simple example of its usage, like making a box move
Re: sock.lua - A simple networking library for LÖVE
Posted: Wed Jun 21, 2017 5:18 am
by Sir_Silver
He has examples of it's usage on the github page.
Re: sock.lua - A simple networking library for LÖVE
Posted: Wed Jun 21, 2017 5:30 am
by yetneverdone
Sir_Silver wrote: ↑Wed Jun 21, 2017 5:18 am
He has examples of it's usage on the github page.
It's a sample on its basic usage, but not a sample about implementing it in a very simple game.
Re: sock.lua - A simple networking library for LÖVE
Posted: Wed Jun 21, 2017 12:33 pm
by Sir_Silver
yetneverdone wrote: ↑Wed Jun 21, 2017 5:30 am
Sir_Silver wrote: ↑Wed Jun 21, 2017 5:18 am
He has examples of it's usage on the github page.
It's a sample on its basic usage, but not a sample about implementing it in a very simple game.
No?
https://github.com/camchenry/sock.lua/t ... mples/pong
Re: sock.lua - A simple networking library for LÖVE
Posted: Wed Jun 21, 2017 1:37 pm
by yetneverdone
Oh a pong sample, sorry i didn't see that.
Re: sock.lua - A simple networking library for LÖVE
Posted: Sat Jun 24, 2017 2:53 pm
by klis
How can I handle a invalid host name?.
Re: sock.lua - A simple networking library for LÖVE
Posted: Sat Jun 24, 2017 10:26 pm
by Ikroth
klis wrote: ↑Sat Jun 24, 2017 2:53 pm
How can I handle a invalid host name?.
Can you post your code? Or at least the code that causes the error? (I'm assuming this will be a call to newServer or newClient)
Re: sock.lua - A simple networking library for LÖVE
Posted: Sun Jun 25, 2017 6:38 am
by klis
Ikroth wrote: ↑Sat Jun 24, 2017 10:26 pm
klis wrote: ↑Sat Jun 24, 2017 2:53 pm
How can I handle a invalid host name?.
Can you post your code? Or at least the code that causes the error? (I'm assuming this will be a call to newServer or newClient)
OK
My scenario is this :
Suppose I started a server @ 192.168.0.100:22122. But I'm trying to connect a server @ 192.168.0.100:2000 or may be the IP I put caused an typo error. How can I handle this.
server
Code: Select all
function love.load()
server = sock.newServer("192.168.0.100", 22122) -- The port here is 22122
.....
.....
end
client
Code: Select all
function love.load()
client = sock.newClient("192.168.0.100", 2000) -- The port here is 2000, this can be another IP
.....
.....
end
How can I handle such scenario / catch those errors ?
Re: sock.lua - A simple networking library for LÖVE
Posted: Sun Jun 25, 2017 11:08 pm
by Ikroth
It sounds like you want to use xpcall (
https://www.lua.org/manual/5.2/manual.html#pdf-xpcall) to handle the error. NOTE: I have linked the Lua 5.2 docs for xpcall. Lua 5.1 does not support passing arguments through xpcall, but 5.2 does and LuaJIT (which LÖVE runs on) has ported this feature.
Code: Select all
local function handleError(err)
print("Error: " .. err)
return err
end
local ok, result = xpcall(sock.newClient, handleError, "192.168.0.1", 12345)
if ok then
-- do something with client
local client = result
else
-- do something with error
local err = result
end
Hopefully this gets you close to what you want.