Exemple #1
0
 public void Disconnect()
 {
     GameMessage msg = new GameMessage();
     msg.fromBytes(GameMessage.disconnectMessage(String.Format("Removing Client {0}", idNumber)));
     _disconnect(idNumber, msg);
     try
     {
         _socket.Send(GameMessage.disconnectMessage("disconnected by server"));
         _socket.Shutdown(SocketShutdown.Both);
         _socket.Close(2);
     }
     catch (Exception se)
     {
         reportError(se.Message);
     }
 }
Exemple #2
0
 void Receive(IAsyncResult result)
 {
     if (BitConverter.ToUInt16(buffer, 0) == GameMessage.Disconnect)
     {
         GameMessage msg = new GameMessage();
         msg.fromBytes(buffer);
         if (disconnect != null)
             disconnect(msg);
         Die();
     }
     else
     {
         if (BitConverter.ToUInt16(buffer, 0) == GameMessage.Initialise)
         {
             id = BitConverter.ToUInt16(buffer, 2);
         }
         else
         {
             GameMessage msg = new GameMessage();
             msg.fromBytes(buffer);
             if (message != null)
                 message(msg);
         }
         if (_socket.Connected)
         {
             try
             {
                 _socket.BeginReceive(buffer, 0, 8192, SocketFlags.None, new AsyncCallback(Receive), this);
             }
             catch (Exception se)
             {
                 Error(se.Message);
             }
         }
     }
 }
Exemple #3
0
 public GameMessage getMessage()
 {
     newChunk = false;
     GameMessage msg = new GameMessage();
     msg.fromBytes(buffer);
     return msg;
 }