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

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
Ikroth
Citizen
Posts: 70
Joined: Thu Jul 18, 2013 4:44 am

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

Post by Ikroth » Fri Jun 16, 2017 7:09 pm

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?

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

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

Post by yetneverdone » Wed Jun 21, 2017 3:24 am

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

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

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

Post by Sir_Silver » Wed Jun 21, 2017 5:18 am

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

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

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

Post by yetneverdone » 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.

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

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

Post by Sir_Silver » 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

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

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

Post by yetneverdone » Wed Jun 21, 2017 1:37 pm

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.

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

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

Post by klis » Sat Jun 24, 2017 2:53 pm

How can I handle a invalid host name?.

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

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

Post by Ikroth » 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)

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

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

Post by klis » Sun Jun 25, 2017 6:38 am

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 ?

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

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

Post by Ikroth » Sun Jun 25, 2017 11:08 pm

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.

Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests