Ejemplo n.º 1
0
 private void SendLogic(AsyncThread thread)
 {
     while (thread.IsWorking())
     {
         doSendMessage();
         System.Threading.Thread.Sleep(20);
     }
 }
Ejemplo n.º 2
0
        public TCPConnector(IPacketFormat packetFormat, IPacketHandlerManager packetHandlerManager) : base(packetFormat, packetHandlerManager)
        {
            mSocket              = null;
            mNetStream           = new NetStream(INetConnector.MAX_SOCKET_BUFFER_SIZE * 2);
            tempReadPacketLength = 0;
            tempReadPacketType   = 0;
            tempReadPacketData   = null;

            mReadCompleteCallback = new AsyncCallback(ReadComplete);
            mSendCompleteCallback = new AsyncCallback(SendComplete);
            mSendThread           = new AsyncThread(SendLogic);
            mSendThread.Start();
        }
Ejemplo n.º 3
0
        public override void Connect(string address, int port)
        {
            SetConnectStatus(ConnectionStatus.CONNECTING);
            base.Connect(address, port);
            mSocket = new TcpClient();
            AsyncThread connectThread = new AsyncThread((thread) => {
                try
                {
                    mSocket.NoDelay = true;                     // set the nodelay mark.
                    mSocket.Connect(mRemoteHost.GetAddress(), mRemoteHost.GetPort());
                    mSocket.GetStream().BeginRead(mNetStream.AsyncPipeIn, 0, INetConnector.MAX_SOCKET_BUFFER_SIZE, mReadCompleteCallback, this);
                    SetConnectStatus(ConnectionStatus.CONNECTED);
                }
                catch (Exception e)
                {
                    LoggerSystem.Instance.Error(e.Message);
                    SetConnectStatus(ConnectionStatus.ERROR);
                }

                CallbackConnected(IsConnected());
            });

            connectThread.Start();
        }