luasocket - lua socket handling multiple connections -


my question lua sockets, have chat , want make bot chat. chat has multiple rooms on defferent servers calculated function called getserver connect function this

function connect(room)    con = socket.tcp()    con:connect(getserver(room), port)    con:settimeout(0)    con:setoption('keepalive', true)    con:send('auth' .. room) 

and function loop be

function main()    while true      rect, r, st = socket.select({con}, nil, 0.2)      if (rect[con] ~= nil)         resp, err, part = con:receive("*l")         if not( resp == nil)             self.events(resp)  end     end        end           end 

now when runs receives data first room , dunno how fix that

try creating array of connections. map of room connections might useful. example:

local connections = {} local roomconnmap = {}  function connect(room)    local con = socket.tcp()    con:connect(getserver(room), port)    con:settimeout(0)    con:setoption('keepalive', true)    con:send('auth' .. room)     table.insert(connections, con)    roomconnmap[room] = con end  function main()    while true      local rect, r, st = socket.select(connections, nil, 0.2)      i, con in ipairs(rect)          resp, err, part = con:receive("*l")         if resp ~= nil             self.events(resp)         end      end    end end 

note rect array of items found connections there data read. in for i,con loop con connection object, not use connections[con] (this doesn't make sense because connections array, not map).


Comments

Popular posts from this blog

android - Get AccessToken using signpost OAuth without opening a browser (Two legged Oauth) -

org.mockito.exceptions.misusing.InvalidUseOfMatchersException: mockito -

google shop client API returns 400 bad request error while adding an item -