diff options
Diffstat (limited to 'sample/dualstack-httpd.rb')
| -rw-r--r-- | sample/dualstack-httpd.rb | 33 |
1 files changed, 16 insertions, 17 deletions
diff --git a/sample/dualstack-httpd.rb b/sample/dualstack-httpd.rb index 11c5201d74..ab02e17aea 100644 --- a/sample/dualstack-httpd.rb +++ b/sample/dualstack-httpd.rb @@ -3,7 +3,6 @@ # The code demonstrates how a multi-protocol daemon should be written. require "socket" -require "thread" port = 8888 res = Socket.getaddrinfo(nil, port, nil, Socket::SOCK_STREAM, nil, Socket::AI_PASSIVE) @@ -29,22 +28,22 @@ end while true as = ls.accept Thread.start do - STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n" - s = as # copy to dynamic variable - str = '' - while line = s.gets - break if line == "\r\n" or line == "\n" - str << line - end - STDERR.print "socket #{myname} got string\n" - s.write("HTTP/1.0 200 OK\n") - s.write("Content-type: text/plain\n\n") - s.write("this is test: my name is #{myname}, you sent:\n") - s.write("---start\n") - s.write(str) - s.write("---end\n") - s.close - STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n" + STDERR.print "socket #{myname} accepted, thread ", Thread.current, "\n" + s = as # copy to dynamic variable + str = '' + while line = s.gets + break if line == "\r\n" or line == "\n" + str << line + end + STDERR.print "socket #{myname} got string\n" + s.write("HTTP/1.0 200 OK\n") + s.write("Content-type: text/plain\n\n") + s.write("this is test: my name is #{myname}, you sent:\n") + s.write("---start\n") + s.write(str) + s.write("---end\n") + s.close + STDERR.print "socket #{myname} processed, thread ", Thread.current, " terminating\n" end end end |
