Ruby 构建一个简单的 TCP 服务器

2015-08-23 0 242
Ruby 构建一个简单的 TCP 服务器
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

遇见资源网 ruby Ruby 构建一个简单的 TCP 服务器 http://www.ox520.com/16450.html

常见问题

相关文章

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

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