Beispiel #1
0
 private void onConnected(IAsyncResult ar)
 {
     if (this.tcpClient.Connected)
     {
         GoWorldLogger.Info(this.ToString(), "Connected " + this.tcpClient.Connected);
     }
     else
     {
         GoWorldLogger.Warn(this.ToString(), "Connect Failed!");
         this.disconnectTCPClient();
     }
 }
Beispiel #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);
        }