TCPServer
core :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Simple server example using a non-blocking `TCPServer`
module socket_simple_server
import socket
if args.is_empty then
print "Usage : socket_simple_server <port>"
exit 1
end
var port = args[0].to_i
# Open the listening socket
var socket = new TCPServer(port)
socket.listen 4
socket.blocking = false
print "Listening on port {socket.port}"
# Loop until a single client connects
var client: nullable TCPStream = null
while client == null do
printn "."
sys.nanosleep(0, 200000)
client = socket.accept
end
print " Connected"
# Communicate
print client.read_line
client.write "Hello client!\n"
print client.read_line
client.write "Bye client!\n"
client.close
lib/socket/examples/socket_simple_server.nit:15,1--50,12