[luci] TCP connection and listening a port

Steven Barth steven at midlink.org
Tue Sep 29 11:44:06 CEST 2009


Using nixio is like using sockets in C, the function calls are very similar.
A small example

require "nixio", require "nixio.util"
mysocket = nixio.bind(nil, 1234) --Port to listen on
mysocket:listen(32)

while true do
  client = mysock:accept()
  if nixio.fork() == 0 then -- Create a new process
    break
  end
  client:close() -- Close client connection in main process
  nixio.wait(nil, "nohang") -- Kill zombies
end

-- This is the client process
data = client:read(1024)
print("Recevied data from client:", data)

client:write("Write data to client")
client:close()


More information about the luci mailing list