Create a network service that sits on TCP port 12321, which accepts connections on that port, and which echoes complete lines (using a carriage-return/line-feed sequence as line separator) back to clients. No error handling is required. For the purposes of testing, it is only necessary to support connections from localhost (127.0.0.1 or perhaps ::1). Logging of connection information to standard output is recommended.

The implementation must be able to handle simultaneous connections from multiple clients. A multi-threaded or multi-process solution may be used. Each connection must be able to echo more than a single line.

The implementation must not stop responding to other clients if one client sends a partial line or stops reading responses.

local socket = require("socket")
 
local function has_value(tab, value)
    for i, v in ipairs(tab) do
        if v == value then return i end
    end
    return false
end
 
local function checkOn(client)
   local line, err = client:receive()
	if line then
		client:send(line .. "\n")
	end
	if err and err ~= "timeout" then
		print(tostring(client) .. " " .. err)
		client:close()
		return true  -- end this connection
   end
	return false  -- do not end this connection
end
 
local server = assert(socket.bind("*",12321))
server:settimeout(0)  -- make non-blocking
local connections = { }  -- a list of the client connections
while true do
	local newClient = server:accept()
	if newClient then
		newClient:settimeout(0)  -- make non-blocking
		table.insert(connections, newClient)
	end
	local readList = socket.select({server, table.unpack(connections)})
	for _, conn in ipairs(readList) do
		if conn ~= server and checkOn(conn) then
			table.remove(connections, has_value(connections, conn))
		end
	end
end