Example #1
0
        void StartConnectThread()
        {
            if (_tcpClient == null)
            {
                _tcpClient                   = new TcpClient();
                _tcpClient.NoDelay           = true;
                _tcpClient.ReceiveBufferSize = TcpClientReceiveBufferSize;
                _tcpClient.ReceiveTimeout    = TcpClientReceiveTimeout;
                _tcpClient.SendBufferSize    = TcpClientSendBufferSize;
                _tcpClient.SendTimeout       = TcpClientSendTimeout;
            }

            _connecter = new ConnectThread(_tcpClient, _hostName, _port, delegate(bool ok)
            {
                Log.Debug("ConnectThread callback: " + ok.ToString());

                if (ok)
                {
                    _taskExecutor.Add(ConnectOK);
                }
                else
                {
                    _taskExecutor.Add(ConnectFail);
                }

                _connecter.ClearCallback();
                _connecter = null;
            });

            _connecter.Run();
        }
Example #2
0
        void ConnectTimeout()
        {
            if (_tcpClient != null && !_tcpClient.Connected)
            {
                Log.Debug("BeginConnect timeout and close socket");

                CloseTcpClient();

                if (_connecter != null)
                {
                    _connecter.ClearCallback();
                    _connecter = null;
                }

                ConnectFail();
            }
        }