Ruby 简单的 UDP 程序示例
- 作者: 呵-只是笑笑
- 来源: 51数据库
- 2022-08-12
require 'socket'
host = 'localhost'
port = 1234
s = UDPSocket.new
s.bind(nil, port)
s.send("1", 0, host, port)
5.times do
text, sender = s.recvfrom(16)
remote_host = sender[3]
puts "#{remote_host} sent #{text}"
response = (text.to_i * 2).to_s
puts "We will respond with #{response}"
s.send(response, 0, host, port)
end
推荐阅读
