Beispiel #1
0
 private void HandleConnectionClosed(Connection connection)
 {
     if (messageHandler.cloning)
     {
         messageHandler.HandleMessage(new Packet(FLAG.ERROR_MESSAGE), connection);
     }
     Thread.Sleep(10000);
     StartListener();
     return;
 }
Beispiel #2
0
 public void myReadCallBack(IAsyncResult ar)
 {
     try
     {
         using (MemoryStream memStream = new MemoryStream(dataStream, 0, dataStream.Length, false))
         {
             bool hasAllZeroes    = dataStream.All(singleByte => singleByte == 0);
             var  myNetworkStream = (NetworkStream)ar.AsyncState;
             if (!hasAllZeroes)
             {
                 try
                 {
                     var packet = xs.Deserialize(memStream) as Packet;
                     if (packet.dataIdentifier != FLAG.Null)
                     {
                         messageHandler.HandleMessage(packet);
                     }
                 }
                 catch (Exception ex)
                 {
                     Console.WriteLine("Problem with parse: " + ex);
                 }
             }
             myNetworkStream.BeginRead(dataStream, 0, dataStream.Length,
                                       new AsyncCallback(myReadCallBack),
                                       myNetworkStream);
         }
     }
     catch
     {
         running = false;
         Console.WriteLine("Something is wrong with socket reading");
     }
 }