Chinaunix
标题:
Ruby 构建支持多客户端的 TCP 网络服务器
[打印本页]
作者:
shift_1
时间:
2011-03-25 14:32
标题:
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
复制代码
作者:
2gua
时间:
2011-03-25 15:52
系统管理,还是比较倾向于Perl。
作者:
Sevk
时间:
2012-04-09 11:09
提示:
作者被禁止或删除 内容自动屏蔽
作者:
lax
时间:
2012-04-12 21:27
while loop里用select,性能和可靠性问题都很大。倾向于用eventmachine来写。
欢迎光临 Chinaunix (http://bbs.chinaunix.net/)
Powered by Discuz! X3.2