Ruby 构建支持多客户端的 TCP 网络服务器

2015-08-17 0 779
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

遇见资源网 ruby Ruby 构建支持多客户端的 TCP 网络服务器 http://www.ox520.com/16457.html

常见问题

相关文章

发表评论
暂无评论
官方客服团队

为您解决烦忧 - 24小时在线 专业服务