Ejemplo n.º 1
0
 void pingHost()
 {
     Task.Factory.StartNew(() =>
     {
         ping  = DateTime.Now;
         var p = Payload.makePayload("ping");
         connector.Send(p);
         NotifyPayload r         = null;
         connector.ReceivedData += (sender, e) =>
         {
             r = e.payload;
         };
         Task t = Task.Factory.StartNew(() =>
         {
             while (r == null)
             {
             }
         });
         t.Wait(1000);
         if (r != null && r.status == "pong" && r.identity == p.identity)
         {
             pong = DateTime.Now;
         }
     });
 }
Ejemplo n.º 2
0
 private void startReceiveLoop()
 {
     Console.WriteLine("Now receiving");
     while (isConnected)
     {
         try
         {
             Console.WriteLine("Waiting for next packet... from " + groupEP.Address.ToString() + ":" + groupEP.Port);
             byte[]        bytes = Socket.Receive(ref groupEP);
             StringBuilder sb    = new StringBuilder();
             sb.Append(Encoding.ASCII.GetString(bytes, 0, bytes.Length));
             Console.WriteLine(sb.ToString());
             try
             {
                 ResponsePayload rp = JsonConvert.DeserializeObject <ResponsePayload>(sb.ToString());
                 if (queueList > 0)
                 {
                     //while (responseWaiter != null)
                     //{
                     //
                     //}
                     responseWaiter = rp;
                 }
             }
             catch
             {
                 Console.WriteLine("Received data is not a response payload!");
             }
             try
             {
                 NotifyPayload r = JsonConvert.DeserializeObject <NotifyPayload>(sb.ToString());
                 if (r.status == "notify")
                 {
                     var ee      = new ConnectorReceiveEventArgs(r);
                     var handler = ReceivedData;
                     if (handler != null)
                     {
                         handler(null, ee);
                     }
                 }
             }
             catch (Exception e)
             {
                 Console.WriteLine("Received data is not a notify payload! " + e.StackTrace);
             }
         }
         catch (SocketException ex)
         {
             isConnected = false;
             Console.WriteLine(ex.StackTrace);
         }
     }
 }
Ejemplo n.º 3
0
 public ConnectorReceiveEventArgs(NotifyPayload rp)
 {
     payload = rp;
 }
Ejemplo n.º 4
0
 public ConnectorReceiveEventArgs(NotifyPayload rp)
 {
     payload = rp;
 }