Beispiel #1
0
 /// <summary>
 /// Connect the socket.
 /// </summary>
 public void Connect(ConnectionInformations connectionInformations)
 {
     //if (m_RawSocket != null && !m_RawSocket.Connected)
     //    RawConnect();
     m_MessageInformations = new MessageInformations(account);
     if (m_IsChangingServer)
     {
         client.Close("Changing server.");
         client = new NetClient();
         this.client.Connected += new EventHandler<NetSocketConnectedEventArgs>(client_Connected);
         this.client.DataArrived += new EventHandler<NetSockDataArrivalEventArgs>(client_DataArrived);
         this.client.Disconnected += new EventHandler<NetSocketDisconnectedEventArgs>(client_Disconnected);
         this.client.ErrorReceived += new EventHandler<NetSockErrorReceivedEventArgs>(client_ErrorReceived);
         this.client.StateChanged += new EventHandler<NetSockStateChangedEventArgs>(client_StateChanged);
     }
     try
     {
         client.Connect(new IPEndPoint(IPAddress.Parse(connectionInformations.Address), connectionInformations.Port));
     }
     catch (SocketException sockEx)
     {
         account.Log(new ErrorTextInformation("[Socket Exception] " + sockEx.Message), 0);
         account.TryReconnect(10);
     }
 }
Beispiel #2
0
 private void SocketReception()
 {
     m_MessageInformations = new MessageInformations(account);
     while ((m_Socket != null) && (Connected()))
     {
         byte[] buffer = new byte[m_Socket.Available];
         if (buffer.Length != 0)
         {
             m_Socket.Receive(buffer);
             account.LatencyFrame.UpdateLatency();
             m_MessageInformations.ParseBuffer(buffer);
         }
     }
     if (!m_ForcedDisconnect)
     {
         account.Log(
         new ErrorTextInformation("La connexion a été interrompue à cause d'une raison inconnue."), 0);
         if (account.IsMITM)
         {
             account.Log(new ErrorTextInformation("MITM : Impossible de se reconnecter."), 0);
             DisconnectServer();
         }
         else
             account.TryReconnect(2);
     }
     m_ForcedDisconnect = false;
 }