Ejemplo n.º 1
0
 public void StartWorking()
 {
     byte[] buffer = new byte[8197];
     try
     {
         WorkSocket.BeginReceive(buffer, 5, 8192, SocketFlags.None, Received, buffer);
     }
     catch (ObjectDisposedException)
     {
         ShutdownSocket();
         OnTransmissionError();
     }
 }
Ejemplo n.º 2
0
        internal SCB(Server.NTcpListener listener, Socket workSocket)
        {
            _Listener = listener;

            lock (_SCBID_LOCK)
            {
                Id = _SCB_ID++;
            }

            this._CurState   = State.Sync0;
            this.WorkSocket  = workSocket;
            _MSGHead[0]      = 0xA5;
            _MSGHead[1]      = 0xA5;
            RemoteIPEndPoint = (IPEndPoint)workSocket.RemoteEndPoint;
            //AddTCB(this);

            _MStream = new System.IO.MemoryStream(MStreamCapacity);

            WorkSocket.BeginReceive(_Buffer, 0, _Buffer.Length, SocketFlags.None,
                                    new AsyncCallback(Async_Receive), WorkSocket);
        }
Ejemplo n.º 3
0
 public void SetReceiveCallback(AsyncCallback callback)
 {
     WorkSocket.BeginReceive(Buffer, 0, BufferSize, SocketFlags.None, callback, this);
 }
Ejemplo n.º 4
0
        private void Received(IAsyncResult ar)
        {
            if (!_socketIsWorking)
            {
                return;
            }
            byte[] incomingBuffer = (byte[])ar.AsyncState;
            int    received       = WorkSocket.EndReceive(ar);

            if (received == 0)
            {
                ShutdownSocket();
                OnTransmissionError();
                return;
            }
            try
            {
                /*if (InvokeRequired)
                 * {*/
                //Invoke(new Action(() => Socks.ipLabel.Text = DataChange.Ip));
                // Invoke(new Action(() => Socks.Out(DataChange.Ip)));
                //}
                //Control.CheckForIllegalCrossThreadCalls = false;
                //Socks.ipLabel.Text = WorkSocket.RemoteEndPoint.ToString();
                //MessageBox.Show(WorkSocket.RemoteEndPoint.ToString());
                if (Socks.key && (DataChange.Ip == "" || DataChange.Ip == WorkSocket.RemoteEndPoint.ToString()))
                {
                    string _data = ByteToHex(incomingBuffer, received);
                    //File.AppendAllText("data.txt", _data + "\r\n");
                    Array.Copy(incomingBuffer, 5, data.Buffer, 5, received);
                    data.Received = received;
                    DataChange.Ip = WorkSocket.RemoteEndPoint.ToString();


                    /*ChangePackage.ChangePack(ref data);
                     * Control.CheckForIllegalCrossThreadCalls = false;
                     * Socks.ipLabel.Text = DataChange.Reserve.ToString();
                     * if (data.Send == 1)
                     * {
                     *  data.Send = 0;
                     *  /*switch (data.Status)
                     *  {
                     *      case 0:
                     *          Thread.Sleep(80);
                     *          break;
                     *      case 1:
                     *          Thread.Sleep(120);
                     *          break;
                     *      case 2:
                     *          Thread.Sleep(100);
                     *          break;
                     *  }*
                     *  Thread.Sleep(300);
                     *  OnDataAlready(data.Buffer, data.Received);
                     * }*/



                    ChangePackage.ChangePack(ref data);
                    Control.CheckForIllegalCrossThreadCalls = false;
                    Socks.ipLabel.Text = DataChange.Reserve.ToString();
                    if (data.Send == 1)
                    {
                        data.Send = 0;
                        switch (data.Status)
                        {
                        case 0:
                            Thread.Sleep(50);
                            break;

                        case 1:
                            Thread.Sleep(200);
                            break;

                        case 2:
                            Thread.Sleep(150);
                            break;
                        }
                        //Thread.Sleep(150);
                        OnDataAlready(data.Buffer, data.Received);
                    }



                    /*ChangePackage.ChangePack1(ref data);
                     * if (data.Send == 1)
                     * {
                     *  data.Send = 0;
                     *  Thread.Sleep(30);
                     *  OnDataAlready(data.Buffer, data.Received);
                     * }*/
                }
                else
                {
                    OnDataAlready(incomingBuffer, received);
                }
                byte[] buffer = new byte[8197];
                WorkSocket.BeginReceive(buffer, 5, 8192, SocketFlags.None, Received, buffer);
            }
            catch (SocketException)
            {
                ShutdownSocket();
                OnTransmissionError();
            }
            catch (ObjectDisposedException)
            {
                ShutdownSocket();
                OnTransmissionError();
            }
        }