- require 'socket'
- server = TCPServer.new(1234)
- while connection = server.accept
- while line = connection.gets
- break if line =~ /quit/
- puts line
- connection.puts "Received!"
- end
- connection.puts "Closing the connection. Bye!"
- connection.close
- end
- # To test
- # telnet 127.0.0.1 1234
- #该片段来自于http://www.codesnippet.cn/detail/110120131525.html
来源: http://www.codesnippet.cn/detail/110120131525.html