core :: union_find
union–find algorithm using an efficient disjoint-set data structure
# Server sample using the Socket module which allow client to connect
module socket_server
import socket
if args.is_empty then
print "Usage : socket_server <port>"
return
end
var socket = new TCPServer(args[0].to_i)
socket.listen 1
print "[PORT] : {socket.port.to_s}"
var clients = new Array[TCPStream]
var max = socket
loop
var fs = new SocketObserver.with_sets(true, true, true)
fs.read_set.add socket
for c in clients do fs.read_set.add c
printn "."
if fs.select(max, 4, 0) == 0 then
print "Error occured in select {sys.errno.strerror}"
break
end
if fs.read_set.has(socket) then
var ns = socket.accept
print "Accepting {ns.address} ... "
print "[Message from {ns.address}] : {ns.read_line}"
ns.write "Hello client.\n"
print "[Message from {ns.address}] : {ns.read_line}"
ns.write "Bye client.\n"
print "Closing {ns.address} ..."
ns.close
end
end
lib/socket/examples/socket_server.nit:17,1--55,3