Connect() 개인적인 메소드

private Connect ( ) : void
리턴 void
예제 #1
0
        public void Connect()
        {
            // Check current connection state
            if (_connection != null)
            {
                switch (_connection.State)
                {
                    case ConnectionState.Connected:
                        Trace.TraceEvent(TraceEventType.Warning, 0, "Attempt to connect when connection is already in 'Connected' state. New attempt has been ignored.");
                        break;
                    case ConnectionState.Connecting:
                        Trace.TraceEvent(TraceEventType.Warning, 0, "Attempt to connect when connection is already in 'Connecting' state. New attempt has been ignored.");
                        break;
                    case ConnectionState.Failed:
                        Trace.TraceEvent(TraceEventType.Error, 0, "Cannot attempt re-connection once in 'Failed' state");
                        throw new PusherException("Cannot attempt re-connection once in 'Failed' state", ErrorCodes.ConnectionFailed);
                }
            }

            var scheme = "ws://";

            if (_options.Encrypted)
                scheme = "wss://";

            // TODO: Fallback to secure?

            string url = String.Format("{0}{1}/app/{2}?protocol={3}&client={4}&version={5}",
                scheme, this.Host, _applicationKey, Settings.Default.ProtocolVersion, Settings.Default.ClientName,
                Settings.Default.VersionNumber);

            _connection = new Connection(this, url);
            _connection.Connected += _connection_Connected;
            _connection.ConnectionStateChanged +=_connection_ConnectionStateChanged;
            _connection.Connect();
        }
        public void Connect()
        {
            // Check current connection state
            if (_connection != null)
            {
                switch (_connection.State)
                {
                    case ConnectionState.Connected:
                        LogWarning("Attempt to connect when connection is already in 'Connected' state. New attempt has been ignored.");
                        break;
                    case ConnectionState.Connecting:
                        LogWarning("Attempt to connect when connection is already in 'Connecting' state. New attempt has been ignored.");
                        break;
                    case ConnectionState.Failed:
                        LogWarning("Cannot attempt re-connection once in 'Failed' state");
                        throw new PusherException("Cannot attempt re-connection once in 'Failed' state", ErrorCodes.ConnectionFailed);
                }
            }

            var scheme = "ws://";

            if (_options.Encrypted)
                scheme = "wss://";

            // TODO: Fallback to secure?

            string url = String.Format("{0}{1}/app/{2}?protocol={3}&client={4}&version={5}",
                scheme, this.Host, _applicationKey, Pusher.PROTOCOL_NUMBER, PusherSettings.ClientName, PusherSettings.ClientVersion
            );

            Log( "Connecting to url: '"+url+"'" );
            _connection = new Connection(this, url);
            _connection.Connected += _connection_Connected;
            _connection.ConnectionStateChanged +=_connection_ConnectionStateChanged;
            _connection.Connect();
        }