3 # The code demonstrates how a multi-protocol daemon should be written.
8 res = Socket.getaddrinfo(nil, port, nil, Socket::SOCK_STREAM, nil, Socket::AI_PASSIVE)
14 s = TCPServer.new(i[3], i[1])
15 n = Socket.getnameinfo(s.getsockname, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV).join(" port ")
20 (0 .. sockpool.size - 1).each do |i|
23 STDERR.print "socket #{mysock} started, address #{myname}\n"
24 threads[i] = Thread.start do # Thread.start cannot be used here!
25 ls = mysock # copy to dynamic variable
27 STDERR.print "socket #{myname} listener started, pid #{$$} thread #{t}\n"
31 STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n"
32 s = as # copy to dynamic variable
35 break if line == "\r\n" or line == "\n"
38 STDERR.print "socket #{myname} got string\n"
39 s.write("HTTP/1.0 200 OK\n")
40 s.write("Content-type: text/plain\n\n")
41 s.write("this is test: my name is #{myname}, you sent:\n")
46 STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n"