Пример #1
0
 public void Receive()
 {
     try
     {
         if (socket != null && socket.Connected && socket.Available >= 0)
         {
             PacotesREQ  pacotes = PacotesREQ.INST();
             byte[]      buffer  = new byte[2];
             SocketError error   = SocketError.InProgress;
             socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, out error, (result) =>
             {
                 try
                 {
                     if (result.IsCompleted && socket.EndReceive(result, out error) >= 0)
                     {
                         buffer = new byte[BitConverter.ToUInt16(buffer, 0) + 2];
                         socket.BeginReceive(buffer, 0, buffer.Length, SocketFlags.None, out error, (IAsyncResult) =>
                         {
                             try
                             {
                                 if (IAsyncResult.IsCompleted && socket.EndReceive(IAsyncResult, out error) >= 0)
                                 {
                                     PacotesREQ.INST().GetPacketGame(this, buffer);
                                     Dados.IniciarThead(Receive);
                                 }
                                 else
                                 {
                                     SockerVerific(null);
                                 }
                             }
                             catch (Exception ex)
                             {
                                 throw ex;
                             }
                         },
                                             socket);
                     }
                     else
                     {
                         SockerVerific(null);
                     }
                 }
                 catch (Exception ex)
                 {
                     throw ex;
                 }
             },
                                 socket);
             SocketMessage(error);
         }
         else
         {
             SockerVerific(null);
         }
     }
     catch (Exception e)
     {
         new _Message().Error(e.ToString());
     }
 }
Пример #2
0
 public void SyncronizeAuthLocation()
 {
     try
     {
         remote = new IPEndPoint(IPAddress.Parse(Carregar.IP), 39190);
         socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.Connect(remote);
         if (socket.Connected)
         {
             LoggerConexão(remote);
             player = new Player
             {
                 AuthClient = new AuthClient(socket, PacotesREQ.INST().read)
             };
         }
     }
     catch (Exception ex)
     {
         new _Message().Error(ex.ToString());
     }
 }
Пример #3
0
 public void SyncronizeGameLocation()
 {
     try
     {
         if (player.AuthClient != null)
         {
             BeginDisconnect(player.AuthClient.socket);
         }
         socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         socket.BeginConnect(player.server, (result) =>
         {
             socket.EndConnect(result);
             if (socket.Connected)
             {
                 LoggerConexão(player.server);
                 player.GameClient = new GameClient(socket, PacotesREQ.INST().read);
             }
         }, socket);
     }
     catch (Exception ex)
     {
         new _Message().Error(ex.ToString());
     }
 }