This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Socket.io server on .lp file
#9
(18.12.2018, 16:57)admin Wrote: Why two websockets? There's one localbus socket which is local UDP broadcast, another one is server-client TCP connection.

This was only theoretically question. I don't understand where in attached code there is the websocket assignment to some port. Because in a few examples which I read always there was some address + port 8080 (probably default for websocket);

Like below:

Code:
local ev = require'ev'

-- create a copas webserver and start listening
local server = require'websocket'.server.ev.listen
{
 -- listen on port 8080
 port = 8080,
 -- the protocols field holds
 --   key: protocol name
 --   value: callback on new connection
 protocols = {
   -- this callback is called, whenever a new client connects.
   -- ws is a new websocket instance
   echo = function(ws)
     ws:on_message(function(ws,message)
         ws:send(message)
       end)

     -- this is optional
     ws:on_close(function()
         ws:close()
       end)
   end
 }
}

-- use the lua-ev loop
ev.Loop.default:loop()
Done is better than perfect
Reply


Messages In This Thread
Socket.io server on .lp file - by buuuudzik - 18.12.2018, 10:13
RE: Socket.io server on .lp file - by admin - 18.12.2018, 10:54
RE: Socket.io server on .lp file - by admin - 18.12.2018, 12:58
RE: Socket.io server on .lp file - by admin - 18.12.2018, 15:38
RE: Socket.io server on .lp file - by admin - 18.12.2018, 16:57
RE: Socket.io server on .lp file - by buuuudzik - 18.12.2018, 17:35
RE: Socket.io server on .lp file - by admin - 18.12.2018, 19:30

Forum Jump: