Ejemplo n.º 1
0
 public void Open(Uri uri, string interfaceName)
 {
     this.socket = IO.Socket(uri);
     socket.On(Socket.EVENT_CONNECT, () =>
     {
         var message        = encoder.CreateMessage();
         message.IsResponse = false;
         message.Action     = "register";
         message.MessageId  = Guid.NewGuid().ToString();
         message.Data       = new
         {
             id       = this.id,
             time     = DateTime.UtcNow,
             contract = interfaceName
         };
         socket.Emit("register", encoder.EncodeMessage(message));
     })
     .On("svcAction", (data) =>
     {
         var token   = JToken.FromObject(data);
         var message = encoder.DecodeMessage(token);
         if (handler != null)
         {
             handler(message);
         }
     })
     .On(Socket.EVENT_ERROR, (data) =>
     {
         System.Diagnostics.Trace.WriteLine(data.ToString());
     });
 }