-->
Page 1 of 2

Server connection event

PostPosted: Thu Jan 08, 2015 11:05 am
by M0ebius
In the following example, it seems that the connection event is not working (using NodeMCU 0.9.5 build 20150108)
At least i never get the "connect" message...
Code: Select alls=net.createServer(net.TCP)
s:listen(8007,function(c)
c:on("receive",function(c,l)
  uart.write(0,l)
  end)
c:on("connection",function(c)   
  print("connect")
  end)
c:on("disconnection",function(c)
  print("disconnect")
  end)
end)

did i do something wrong, or is this behavior unintentional?

Re: Server connection event

PostPosted: Thu Jan 08, 2015 11:29 am
by ThomasW
M0ebius wrote:In the following example, it seems that the connection event is not working (using NodeMCU 0.9.5 build 20150108)
At least i never get the "connect" message...
Code: Select alls=net.createServer(net.TCP)
s:listen(8007,function(c)
c:on("receive",function(c,l)
  uart.write(0,l)
  end)
c:on("connection",function(c)   
  print("connect")
  end)
c:on("disconnection",function(c)
  print("disconnect")
  end)
end)

did i do something wrong, or is this behavior unintentional?


The callback in s:listen() gets the "connection"-event:

Code: Select alls=net.createServer(net.TCP)
s:listen(8007,function(c)
c:on("receive",function(c,l)
  uart.write(0,l)
  end)
c:on("disconnection",function(c)
  print("disconnect")
  end)
-- Handle the initial connection:
 print("connect")
end)


Thomas

Re: Server connection event

PostPosted: Thu Jan 08, 2015 3:28 pm
by M0ebius
Thanks Thomas for your fast help!
So it's only a problem with the docu (nodemcu wiki).

Re: Server connection event

PostPosted: Fri Jan 09, 2015 3:20 am
by picpic020960
Bonjour

also why c:on("connection" ... event ?

or

what is a 'not initial connection' ?

thanks