// methods
 public void ConnectionFailed(ConnectionId connectionId, Exception exception)
 {
     _first.ConnectionFailed(connectionId, exception);
     _second.ConnectionFailed(connectionId, exception);
 }
Exemple #2
0
        private void ClientThread()
        {
            try
            {
                if (connectionListener != null)
                {
                    connectionListener.ConnectionStarted();
                }
                VRCModLogger.Log("[VRCMODNW] Connecting to server...");
                socket = new TcpClient();
                socket.ReceiveTimeout = 10000; //10s
                socket.Connect(address, port);
                sslStream = new SslStream(
                    socket.GetStream(),
                    false,
                    new RemoteCertificateValidationCallback(ValidateServerCertificate),
                    null
                    );
                sslStream.AuthenticateAsClient(address);
                string ln;

                inputStream = new StreamReader(sslStream);
                VRCModLogger.Log("[VRCMODNW] Waiting for connection...");
                if (connectionListener != null)
                {
                    connectionListener.WaitingForConnection();
                }
                while ((ln = inputStream.ReadLine()) != null && ln != "READY")
                {
                    ;
                }

                VRCModLogger.Log("[VRCMODNW] Connecting...");
                if (connectionListener != null)
                {
                    connectionListener.Connecting();
                }
                WriteLine("VRCMODNW_" + clientVersion);
                if ((ln = ReadLine()) == null || !ln.Equals("OK"))
                {
                    throw new Exception("Connection aborted");
                }

                socket.ReceiveTimeout = -1; //no receive timeout

                VRCModLogger.Log("[VRCMODNW] Connected.");
                if (connectionListener != null)
                {
                    connectionListener.Connected();
                }
            }
            catch (Exception e)
            {
                VRCModLogger.LogError("[VRCMODNW] Unable to connect: " + e);
                if (connectionListener != null)
                {
                    connectionListener.ConnectionFailed(e.ToString());
                }
                return;
            }
            try
            {
                socket.ReceiveTimeout = 7000;
                listen = true;
                if (!keepaliveThread.IsAlive)
                {
                    keepaliveThread.Start();
                }
                Listen();
                if (connectionListener != null)
                {
                    connectionListener.Disconnected("Connection closed");
                }
            }
            catch (Exception e)
            {
                VRCModLogger.LogError("[VRCMODNW] Disconnected from server: " + e);
                if (connectionListener != null)
                {
                    connectionListener.Disconnected(e.ToString());
                }
            }
        }
 // methods
 /// <inheritdoc/>
 public void ConnectionFailed(ConnectionFailedEvent @event)
 {
     _first.ConnectionFailed(@event);
     _second.ConnectionFailed(@event);
 }