public TcpConnectionHandler(TcpClient client)
        {
            Receiver    = new TcpReceiver(client);
            Sender      = new TcpSender(client);
            ProcessSema = new Semaphore(1, 1);

            ConnectionMainThread = new Thread(MainLoop);
            ConnectionMainThread.Start();
        }
 public virtual void Init(TcpClient client)
 {
     Receiver             = new TcpReceiver(client);
     Sender               = new TcpSender(client);
     ProcessSema          = new Semaphore(1, 1);
     this.Client          = client;
     ConnectionMainThread = new Thread(MainLoop);
     ConnectionMainThread.Start();
     client.ReceiveTimeout = 100000000;
 }
        public void Disconnect(string reason)
        {
            var jstr = JsonWorker.MakeSampleJson(new string[] { "type", "result", "state" }, new string[] { "1", reason, "200" }).jstr;

            this.Sender.WriteSendData(jstr);
            Client.Client.Disconnect(false);
            Client.Close();

            this.Sender   = null;
            this.Receiver = null;
            this.Client.Dispose();
            ProcessSema.Close();
            ProcessSema = null;

            //ConnectThread.Abort();
            OnDisconnect(reason);
        }