## sock.lua - A simple networking library for LÖVE

Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

### Re: sock.lua - A simple networking library for LÖVE

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?

yetneverdone
Party member
Posts: 302
Joined: Sat Sep 24, 2016 11:20 am
Contact:

### Re: sock.lua - A simple networking library for LÖVE

It would be awesome if you could provide a simple example of its usage, like making a box move

Sir_Silver
Party member
Posts: 284
Joined: Mon Aug 22, 2016 2:25 pm

### Re: sock.lua - A simple networking library for LÖVE

He has examples of it's usage on the github page.

yetneverdone
Party member
Posts: 302
Joined: Sat Sep 24, 2016 11:20 am
Contact:

### Re: sock.lua - A simple networking library for LÖVE

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.

Sir_Silver
Party member
Posts: 284
Joined: Mon Aug 22, 2016 2:25 pm

### Re: sock.lua - A simple networking library for LÖVE

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

yetneverdone
Party member
Posts: 302
Joined: Sat Sep 24, 2016 11:20 am
Contact:

### Re: sock.lua - A simple networking library for LÖVE

Sir_Silver wrote:
Wed Jun 21, 2017 12:33 pm
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
Oh a pong sample, sorry i didn't see that.

klis
Prole
Posts: 8
Joined: Mon Jan 27, 2014 4:07 pm

### Re: sock.lua - A simple networking library for LÖVE

How can I handle a invalid host name?.

Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

### Re: sock.lua - A simple networking library for LÖVE

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)

klis
Prole
Posts: 8
Joined: Mon Jan 27, 2014 4:07 pm

### Re: sock.lua - A simple networking library for LÖVE

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 ?

Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

### Re: sock.lua - A simple networking library for LÖVE

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.

### Who is online

Users browsing this forum: No registered users and 6 guests