1

I am able to send a message to a udp socket in Ruby 1.9x. I need to make this backwards compatible to Ruby 1.8.7, but I am not able to find any documentation on how to do this. Here's what I have for 1.9.x:

require 'socket'
socket = Socket.new(:INET, :DGRAM)
addr = Socket.sockaddr_in(UDP_PORT, UDP_HOST)
socket.connect_nonblock addr
socket.send(some_json_string, 0)
socket.close
4

1 回答 1

2

这适用于 1.8.7:

socket = UDPSocket.new
socket.send(payload, 0, UDP_HOST, UDP_PORT)
socket.close
于 2013-05-21T20:52:26.350 回答