Lua-enet, client keeps giving error no matter what I do

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Sharkinmytea
Prole
Posts: 11
Joined: Wed Sep 30, 2015 6:03 pm

Lua-enet, client keeps giving error no matter what I do

Post by Sharkinmytea »

I, I'm trying to make a little server which could receive a packed table as a string, unpack it, calculate stuff on it and return it as a packed table. The problem is that i've used this tutorial http://leafo.net/lua-enet/#tutorial and tried to adapt it to love with the callbacks.
This is the code i ''made'':

Server:

Code: Select all

require('enet')
message ='Default message!'

local host = enet.host_create("localhost:6789")
function love.update(dt)
  local event = host:service(100)
  if event then
    if event.type == "receive" then
    message = "Got message: "..event.data
    event.peer:send( "pong" )
    elseif event.type == "connect" then
	message =  " connected." ..event.data
    elseif event.type == "disconnect" then
	message = " disconnected."
    end
    event = host:service()
  end
end

function love.draw()
love.graphics.setColor(255, 255, 255)
love.graphics.print(message,100,100)
end
Client:

Code: Select all

require('enet')
 port = 25565

 host = enet.host_create()
 server = host:connect("localhost:6789")


function love.update(dt)

local done = false
   event = host:service(100)
   event.peer:send("hello SERVER") --LINE 12
  if event then
    if event.type == "connect" then
      print("Connected to", event.peer)
      event.peer:send("hello SERVE, IM CONNECTED")
    elseif event.type == "receive" then
      print("Got message from server: ", event.data, event.peer)
      done = true
    end
  end

end
When I try to launch the server, it works properly, it shows this Image
and when i launch the client it gives this Image
But the client becomes: Image
Hey, i'm not a native english speaker, so if you think the word I used is not the one I meant, please tell me :)
User avatar
Sharkinmytea
Prole
Posts: 11
Joined: Wed Sep 30, 2015 6:03 pm

Re: Lua-enet, client keeps giving error no matter what I do

Post by Sharkinmytea »

Mmmmmm, quick update, and an important one at that.
It seems the client fails only when i resize or move the server window.
What the hell is this problem and how can i solve it?
Hey, i'm not a native english speaker, so if you think the word I used is not the one I meant, please tell me :)
User avatar
Jasoco
Inner party member
Posts: 3726
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Lua-enet, client keeps giving error no matter what I do

Post by Jasoco »

Not sure how to solve it, but I can tell you why it might have a problem.

On Windows, when you move or resize the window, Update and Draw do not fire. i.e the run loop pauses. On OS X this happens when you hold the mouse down on one of the traffic light buttons or resize. And on Linux I think it's either the Windows or Mac method. This is an issue with SDL or something that Löve uses and cannot be fixed by the devs. We've had discussion about this "problem" but never in the capacity of network data.

I'm betting that when you pause the execution, one is sending out data that isn't being received on the other end.

To solve, try playing around. Use a console and print some messages to it at different parts in the code. Maybe start by changing it so line 12 (The event.peer:send() line) has an if event then around it or is within that if event line below.

I'm sure someone else can chime in as usual. I haven't had any success with actually getting networking working myself.
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Lua-enet, client keeps giving error no matter what I do

Post by Nixola »

I think the Linux behaviour depends on the windows manager, I've never had LÖVE lock when moving or resizing using i3wm.
If you need the server to have an actual window, instead of just running in a console, you might want to put the networking code in a thread.
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
User avatar
s-ol
Party member
Posts: 1077
Joined: Mon Sep 15, 2014 7:41 pm
Location: Cologne, Germany
Contact:

Re: Lua-enet, client keeps giving error no matter what I do

Post by s-ol »

Code: Select all

local done = false
   event = host:service(100)
   event.peer:send("hello SERVER") --LINE 12
  if event then
....
should be

Code: Select all

local done = false
   event = host:service(100)
  if event then
   event.peer:send("hello SERVER") --LINE 12
....
event is nil when nothing happened since the last call, and your line 12 assumes that event exists.

s-ol.nu /blog  -  p.s-ol.be /st8.lua  -  g.s-ol.be /gtglg /curcur

Code: Select all

print( type(love) )
if false then
  baby:hurt(me)
end
User avatar
Sharkinmytea
Prole
Posts: 11
Joined: Wed Sep 30, 2015 6:03 pm

Re: Lua-enet, client keeps giving error no matter what I do

Post by Sharkinmytea »

I've played around with my code and I think nixola is correct, Problem ''solved'', i'll have to live with that!
Hey, i'm not a native english speaker, so if you think the word I used is not the one I meant, please tell me :)
User avatar
Nixola
Inner party member
Posts: 1949
Joined: Tue Dec 06, 2011 7:11 pm
Location: Italy

Re: Lua-enet, client keeps giving error no matter what I do

Post by Nixola »

What solllos points out is also true though
lf = love.filesystem
ls = love.sound
la = love.audio
lp = love.physics
lt = love.thread
li = love.image
lg = love.graphics
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests