Example #1
0
        private Protocol.RegisterServiceResponse Initialize()
        {
            NetMQ.Sockets.RequestSocket req = new NetMQ.Sockets.RequestSocket();
            req.Connect(ServerAddress.RegisterServiceAddress);
            var stream = new System.IO.MemoryStream();

            ProtoBuf.Serializer.Serialize(stream, new Tomato.Net.Protocol.RegisterService()
            {
                ServiceName  = ServiceName,
                ProtocolList = MessageHandle.Instance.DicHandles.Keys.Select(i => (int)i).ToList(),
                IsRegister   = true,
            });
            if (req.TrySendFrame(stream.ToArray()))
            {
                return(ProtoBuf.Serializer.Deserialize <Protocol.RegisterServiceResponse>(new System.IO.MemoryStream(req.ReceiveFrameBytes())));
            }
            return(null);
        }
Example #2
0
 /// <summary>
 /// 初始化服务模块
 /// 在这里,我们将已注册的protocolID发送到路由端 Tomato.RouteService
 /// </summary>
 /// <returns></returns>
 private ResRegisterService _InitializeService(bool isRegister = true)
 {
     Logger.Debug($"{this.ServiceName} 正在向路由注册模块...");
     NetMQ.Sockets.RequestSocket req = new NetMQ.Sockets.RequestSocket();
     req.Connect(ServerAddress.RegisterServiceAddress);
     using (var stream = new System.IO.MemoryStream())
     {
         ProtoBuf.Serializer.Serialize(stream, new ReqRegisterService()
         {
             ServiceName  = ServiceName,
             ProtocolList = MessageHandle.DicHandles.Keys.Select(i => (int)i).ToList(),
             IsRegister   = isRegister,
         });
         if (req.TrySendFrame(stream.ToArray()))
         {
             return(ProtoBuf.Serializer.Deserialize <ResRegisterService>(new System.IO.MemoryStream(req.ReceiveFrameBytes())));
         }
     }
     return(null);
 }