从网上搜到的...了解一下Ruby的Socket编程
require "socket"
class IPMSG
IPMSG_PORT = 2425
VERSION = "1"
COMMAND = "32" #send msg
def initialize(user, port = IPMSG_PORT)
@user = user
@port = port
@sock = UDPSocket.new
end
def send(target, msg)
s = [VERSION,rand(100),target,@user,COMMAND,msg].join(":")
puts s
@sock.connect target, @port
@sock.send s, 0
end
end
#----------------------------------------------------------------
ipmsg = IPMSG.new("dyw")
ipmsg.send "210.25.23.174","hi,ruby ipmsg test"