Exemplo n.º 1
0
        private void Process(AsyncThread thread)
        {
            while (thread.IsWorking())
            {
                ((TaskProcessor)thread.GetExtraData()).HandleTasks(50);

                System.Threading.Thread.Sleep(10);
            }
        }
Exemplo n.º 2
0
        private void SendLogic(AsyncThread thread)
        {
            while (thread.IsWorking())
            {
                doSendMessage();

                System.Threading.Thread.Sleep(30);
            }
        }
Exemplo n.º 3
0
        public WebSocketConnector(IPacketFormat packetFormat, IPacketHandlerManager packetHandlerManager) : base(packetFormat, packetHandlerManager)
        {
            mSocket              = null;
            mNetStream           = new NetStream(INetConnector.MAX_SOCKET_BUFFER_SIZE * 2);
            tempReadPacketLength = 0;
            tempReadPacketType   = 0;
            tempReadPacketData   = null;

            mSendThread = new AsyncThread(SendLogic);
            mSendThread.Start();
        }
Exemplo n.º 4
0
        public WebSocketConnector(IPacketFormat packetFormat, IPacketHandlerManager packetHandlerManager)
            : base(packetFormat, packetHandlerManager)
        {
            mSocket = null;
            mNetStream = new NetStream(INetConnector.MAX_SOCKET_BUFFER_SIZE * 2);
            tempReadPacketLength = 0;
            tempReadPacketType = 0;
            tempReadPacketData = null;

            mSendThread = new AsyncThread(SendLogic);
            mSendThread.Start();
        }
Exemplo n.º 5
0
        public UDPConnector(IPacketFormat packetFormat, IPacketHandlerManager packetHandlerManager) : base(packetFormat, packetHandlerManager)
        {
            mSocket              = null;
            mRemoteEndPoint      = 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();
        }
Exemplo n.º 6
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.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();
        }
Exemplo n.º 7
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.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 ();
        }
Exemplo n.º 8
0
        public TaskProcessor GetProcessor()
        {
            AsyncThread at = mThreadList[(mIndexRnd++) % mThreadCount];

            return((TaskProcessor)at.GetExtraData());
        }
Exemplo n.º 9
0
        private void SendLogic(AsyncThread thread)
        {
            while (thread.IsWorking())
            {
                doSendMessage();

                System.Threading.Thread.Sleep(30);
            }
        }