Exemple #1
0
        /// <summary>
        /// Starts flow processing.
        /// </summary>
        internal void Start()
        {
            // Move processing to thread pool.
            AutoResetEvent startLock = new AutoResetEvent(false);

            ThreadPool.QueueUserWorkItem(new WaitCallback(delegate(object state){
                lock (m_pLock){
                    startLock.Set();

                    // TCP / TLS client, connect to remote end point.
                    if (!m_IsServer && m_Transport != SIP_Transport.UDP)
                    {
                        try{
                            TCP_Client client = new TCP_Client();
                            client.Connect(m_pLocalEP, m_pRemoteEP, m_Transport == SIP_Transport.TLS);

                            m_pTcpSession = client;

                            BeginReadHeader();
                        }
                        catch {
                            Dispose();
                        }
                    }
                }
            }));
            startLock.WaitOne();
            startLock.Close();
        }
Exemple #2
0
            /// <summary>
            /// 连接服务器
            /// </summary>
            /// <param name="ErrorDescription"></param>
            /// <returns></returns>
            public bool Connect(ref string ErrorDescription)
            {
                ErrorDescription = "";

                try
                {
                    tcpClient.Connect(HostNameOrIP, Port);

                    if (tcpClient.IsConnected)
                    {
                        return(true);
                    }
                    else
                    {
                        ErrorDescription = "连接服务器失败。";

                        return(false);
                    }
                }
                catch (Exception e)
                {
                    ErrorDescription = e.Message;

                    return(false);
                }
            }
Exemple #3
0
        private void Form1_Load(object sender, EventArgs e)
        {
            con = new TCP_Client <Client>();

            listBox1.DataSource = con.otherClients;
            con.Connect();
        }
Exemple #4
0
 public override void Connect(string host, int port, bool ssl)
 {
     try
     {
         m_pClient.Connect(host, port, ssl);
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Exemple #5
0
        /// <summary>
        /// Connects to the specified LumiSoft mail server.
        /// </summary>
        /// <param name="host">Host name or IP of server to connect.</param>
        /// <param name="userName">User name.</param>
        /// <param name="password">Password.</param>
        public void Connect(string host, string userName, string password)
        {
            if (m_Connected)
            {
                return;
            }

            m_pClient.Connect(host, 5252);

            // Read greeting text
            string response = ReadLine();

            if (!response.StartsWith("+OK"))
            {
                m_pClient.Disconnect();

                throw new Exception(response);
            }

            // Auth user
            m_pClient.TcpStream.WriteLine("LOGIN " + TextUtils.QuoteString(userName) + " " + TextUtils.QuoteString(password));

            response = ReadLine();
            if (!response.StartsWith("+OK"))
            {
                m_pClient.Disconnect();

                throw new Exception(response);
            }

            m_Connected = true;
            m_Host      = host;
            m_UserName  = userName;

            m_pTimerNoop           = new Timer(30000);
            m_pTimerNoop.AutoReset = true;
            m_pTimerNoop.Elapsed  += new ElapsedEventHandler(m_pTimerNoop_Elapsed);
            m_pTimerNoop.Enabled   = true;
        }
Exemple #6
0
        /// <summary>
        /// Starts flow processing.
        /// </summary>
        internal void Start()
        {
            // Move processing to thread pool.
            AutoResetEvent startLock = new AutoResetEvent(false);
            ThreadPool.QueueUserWorkItem(delegate
                                             {
                                                 lock (m_pLock)
                                                 {
                                                     startLock.Set();

                                                     // TCP / TLS client, connect to remote end point.
                                                     if (!m_IsServer && m_Transport != SIP_Transport.UDP)
                                                     {
                                                         try
                                                         {
                                                             TCP_Client client = new TCP_Client();
                                                             client.Connect(m_pLocalEP,
                                                                            m_pRemoteEP,
                                                                            m_Transport == SIP_Transport.TLS);

                                                             m_pTcpSession = client;

                                                             BeginReadHeader();
                                                         }
                                                         catch
                                                         {
                                                             Dispose();
                                                         }
                                                     }
                                                 }
                                             });
            startLock.WaitOne();
        }