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