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来写。
页: [1]
查看完整版本: Ruby 构建支持多客户端的 TCP 网络服务器