`
cxh116
  • 浏览: 75246 次
  • 性别: Icon_minigender_1
  • 来自: 湖南
社区版块
存档分类
最新评论

ruby 简单实现的ipmsg

阅读更多
从网上搜到的...了解一下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"


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics