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: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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?
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post by yetneverdone »

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: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

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

Post by Sir_Silver »

He has examples of it's usage on the github page.
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post 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.
User avatar
Sir_Silver
Party member
Posts: 286
Joined: Mon Aug 22, 2016 2:25 pm
Contact:

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

Post 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
User avatar
yetneverdone
Party member
Posts: 448
Joined: Sat Sep 24, 2016 11:20 am
Contact:

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

Post by yetneverdone »

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: 9
Joined: Mon Jan 27, 2014 4:07 pm
Contact:

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

Post by klis »

How can I handle a invalid host name?.

Code: Select all

Class = require('libs.hump.class')
Play = Class{}
function Play:myGames()
	return 'https://indrajith.dev'
end
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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)
User avatar
klis
Prole
Posts: 9
Joined: Mon Jan 27, 2014 4:07 pm
Contact:

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

Post 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 ?

Code: Select all

Class = require('libs.hump.class')
Play = Class{}
function Play:myGames()
	return 'https://indrajith.dev'
end
User avatar
Ikroth
Citizen
Posts: 79
Joined: Thu Jul 18, 2013 4:44 am

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

Post 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.
Post Reply

Who is online

Users browsing this forum: Amazon [Bot], Bing [Bot] and 5 guests