Class: ExistRuby
- Inherits:
-
Object
- Object
- ExistRuby
- Defined in:
- lib/ExistRuby.rb
Constant Summary collapse
- SERVICEPUBLISH =
服务发布。
0
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize ⇒ ExistRuby
constructor
A new instance of ExistRuby.
-
#publishService(lanServiceName, lanServicePort, lanServiceProtocolType) ⇒ Object
Publish a service to the LAN.
Constructor Details
#initialize ⇒ ExistRuby
Returns a new instance of ExistRuby.
27 28 29 30 31 32 |
# File 'lib/ExistRuby.rb', line 27 def initialize host = '239.173.40.5' #组播组主机地址。 port = 11500 #组播组端口。 @networkThread = EM::open_datagram_socket(host, port, MulticastHandler) end |
Class Method Details
.processMessage(data) ⇒ Object
处理消息
14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/ExistRuby.rb', line 14 def self.processMessage(data) # 处理消息 =CBOR.decode(data) # 解析消息。 #puts "message object: #{messageObject}" # Debug if ['messageType']==0 # 服务发布消息。 servicePublishMessage=CBOR.decode(['servicePublishMessage']) #puts "service publish message: #{servicePublishMessage}" # Debug. @@controller.reportServiceDetected(servicePublishMessage['name'], servicePublishMessage['port'], servicePublishMessage['protocolType']) # 报告已经发现了服务。 else # 服务探测消息。 end end |
.setController(controller) ⇒ Object
10 11 12 |
# File 'lib/ExistRuby.rb', line 10 def self.setController(controller) @@controller=controller # 记录 end |
Instance Method Details
#publishService(lanServiceName, lanServicePort, lanServiceProtocolType) ⇒ Object
Publish a service to the LAN.
Example:
>> existRuby=ExistRuby.new
>> existRuby.publishService("fp_serverPython", 10086, exist::ServicePublishMessage::ServiceProtocolType::GRPC)
Arguments:
lanServiceName: (String)
lanServicePort: (int)
lanServiceProtocolType: (enum)
44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 |
# File 'lib/ExistRuby.rb', line 44 def publishService(lanServiceName, lanServicePort, lanServiceProtocolType) #existMessage=Com::Stupidbeauty::Exist::ExistMessage.new #消息体。 #existMessage.messageType= Com::Stupidbeauty::Exist::ExistMessage::MessageType::SERVICEPUBLISH #设置消息类型。 #existMessage.servicePublishMessage=Com::Stupidbeauty::Exist::ServicePublishMessage.new #创建服务发布消息体。 #existMessage.servicePublishMessage.name=lanServiceName #设置服务名字。 #existMessage.servicePublishMessage.port=lanServicePort #设置端口号。 #existMessage.servicePublishMessage.protocolType=lanServiceProtocolType #设置协议类型。 #packageString=Com::Stupidbeauty::Exist::ExistMessage.encode(existMessage) #序列化为字符串。 servicePublishMessage={} # 服务发布消息。 servicePublishMessage['name']=lanServiceName # 服务名字。 servicePublishMessage['port']=lanServicePort # 服务端口 servicePublishMessage['protocolType']=lanServiceProtocolType # 协议类型。 servicePublishMessageBytteArray=servicePublishMessage.to_cbor # 服务发布消息体。 existMessage={} # 我存在消息体。 existMessage['messageType']=SERVICEPUBLISH # 服务发布。 existMessage['servicePublishMessage']=servicePublishMessageBytteArray # 服务发布消息体。 replyByteArray = existMessage.to_cbor # # 打包成字节数组。 #发送: @networkThread.castData(replyByteArray) #发送数据。 end |