Ruby 构建支持多客户端的 TCP 网络服务器
require 'socket'server = TCPServer.new(1234)
loop do
Thread.start(server.accept) do |connection|
while line = connection.gets
break if line =~ /quit/
puts line
connection.puts "Received!"
end
connection.puts "Closing the connection. Bye!"
connection.close
end
end 系统管理,还是比较倾向于Perl。 while loop里用select,性能和可靠性问题都很大。倾向于用eventmachine来写。
页:
[1]