Пример #1
0
 public void Connect(ConnectionInformations connectionInformations)
 {
     //if (MainForm.ActualMainForm.IpAdressChoice.SelectedIndex > -1)
     //{
     // IPEndPoint e = new IPEndPoint(new IPAddress(GetBytes(MainForm.ActualMainForm.IpAdressChoice.SelectedText)), 0);
     // m_Socket.Bind(e);
     //}
     if (m_RawSocket != null && !m_RawSocket.Connected)
         RawConnect();
     if (m_IsChangingServer)
     {
         m_Socket.Disconnect(false);
         m_Socket.Dispose();
         m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
         account.State = "Déconnecté";
     }
     try
     {
         m_Socket.Connect(connectionInformations.Address, connectionInformations.Port);
         if (m_Socket.Connected)
         {
             account.State = "Connecté";
             account.LatencyFrame = new LatencyFrame(account);
             account.Log(new ConnectionTextInformation("Connexion établie au serveur " + connectionInformations.ServerName + "."), 0);
             if ((!m_IsChangingServer))
             {
                 m_ReceptionThread = new Thread(SocketReception);
                 m_ReceptionThread.Start();
             }
             m_IsChangingServer = false;
         }
         else
             account.Log(new ConnectionTextInformation("Connexion échouée."), 0);
     }
     catch (SocketException sockEx)
     {
         account.Log(new ErrorTextInformation("[Socket Exception] " + sockEx.Message), 0);
         account.TryReconnect(1);
     }
 }
Пример #2
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);
     }
 }