示例#1
0
 private void disconnectTCPClient()
 {
     if (this.tcpClient != null)
     {
         this.tcpClient.Close();
         this.tcpClient        = null;
         this.packetReceiver   = null;
         this.startConnectTime = DateTime.MinValue;
         GoWorldLogger.Warn(this.ToString(), "Disconnected");
     }
 }
示例#2
0
        private void assureTCPClientConnected()
        {
            if (this.tcpClient != null)
            {
                if (!this.tcpClient.Connected)
                {
                    this.checkConnectTimeout();
                }
                return;
            }

            // no tcpClient == not connecting, start new connection ...
            GoWorldLogger.Info(this.ToString(), "Connecting ...");
            this.tcpClient                   = new TcpClient(AddressFamily.InterNetwork);
            this.tcpClient.NoDelay           = true;
            this.tcpClient.SendTimeout       = 5000;
            this.tcpClient.ReceiveBufferSize = Proto.MAX_PAYLOAD_LEN + Proto.SIZE_FIELD_SIZE;
            this.startConnectTime            = DateTime.Now;
            this.packetReceiver              = new PacketReceiver(this.tcpClient);
            this.tcpClient.Connect(this.Host, this.Port);
            this.tcpClient.Client.Blocking = false;
            //this.tcpClient.BeginConnect(this.Host, this.Port, this.onConnected, null); // TODO: BeginConnect fail in Unity3D
            this.onConnected(null);
        }