예제 #1
0
 public ConnectionFactory(GremlinServer gremlinServer, IMessageSerializer messageSerializer,
                          WebSocketSettings webSocketSettings, string sessionId)
 {
     _gremlinServer     = gremlinServer;
     _messageSerializer = messageSerializer;
     _sessionId         = sessionId;
     _webSocketSettings = webSocketSettings;
 }
      public WebSocketSpinner(WebSocketClient supportingClient, WebSocketUser newUser, WebSocketSettings settings) 
         : base("WebsocketSpinner", settings.ShutdownTimeout)
      {
         connection = new WebSocketConnection(supportingClient, newUser, settings.LogProvider);
         this.settings = settings;

         //Fix up the user so it does what we want.
         User.SetSendPlaceholder((message) =>
         {
            if(connection.Client != null)
               connection.Client.QueueMessage(message);
         });
         User.SetCloseSelfPlaceholder(() =>
         {
            connection.Client.QueueRaw(WebSocketFrame.GetCloseFrame().GetRawBytes());
         });
      }
예제 #3
0
 public Server(RootModel model, SessionManager sessions, WebSocketSettings settings)
 {
     this.model    = model;
     this.sessions = sessions;
     clients       = new HashSet <ClientHandler>();
     (prefix, prefixPath, relativeUri) = SplitUri(settings?.Uri);
     preSharedSecret               = string.IsNullOrWhiteSpace(settings?.PreSharedSecret) ? null : settings.PreSharedSecret.Trim();
     globalPerms                   = settings?.GlobalPermissions ?? WebSocketPermissions.DefaultGlobal;
     networkPerms                  = settings?.NetworkPermissions ?? WebSocketPermissions.DefaultNetwork;
     unauthPerms                   = settings?.UnauthenticatedPermissions ?? WebSocketPermissions.DefaultUnauthenticated;
     model.PropertyChanged        += Model_PropertyChanged;
     model.SessionPropertyChanged += Model_SessionPropertyChanged;
     model.ChannelPropertyChanged += Model_ChannelPropertyChanged;
     if (null != prefix)
     {
         Start();
     }
 }
        private async Task <WebSocket> CreateWebSocketWithFactoryAsync(X509Certificate2 certificate, TimeoutHelper timeoutHelper)
        {
            Contract.Assert(_connectionFactory != null, "Invalid call: CreateWebSocketWithFactory.");

            if (WcfEventSource.Instance.WebSocketCreateClientWebSocketWithFactoryIsEnabled())
            {
                WcfEventSource.Instance.WebSocketCreateClientWebSocketWithFactory(EventTraceActivity, _connectionFactory.GetType().FullName);
            }

            // Create the client WebSocket with the factory.
            WebSocket ws;

            try
            {
                if (certificate != null)
                {
                    throw ExceptionHelper.PlatformNotSupported("client certificates not supported yet");
                }
                var headers = new WebHeaderCollection();
                headers[WebSocketTransportSettings.SoapContentTypeHeader] = _channelFactory.WebSocketSoapContentType;
                if (_channelFactory.MessageEncoderFactory is BinaryMessageEncoderFactory)
                {
                    headers[WebSocketTransportSettings.BinaryEncoderTransferModeHeader] = _channelFactory.TransferMode.ToString();
                }

                var credentials = _channelFactory.GetCredentials();
                ws = await _connectionFactory.CreateWebSocketAsync(Via, headers, credentials, WebSocketSettings.Clone(), timeoutHelper);
            }
            catch (Exception e)
            {
                if (Fx.IsFatal(e))
                {
                    throw;
                }

                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Format(SR.ClientWebSocketFactory_CreateWebSocketFailed, _connectionFactory.GetType().Name), e));
            }

            // The returned WebSocket should be valid (non-null), in an opened state and with the same SubProtocol that we requested.
            if (ws == null)
            {
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Format(SR.ClientWebSocketFactory_InvalidWebSocket, _connectionFactory.GetType().Name)));
            }

            if (ws.State != WebSocketState.Open)
            {
                ws.Dispose();
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Format(SR.ClientWebSocketFactory_InvalidWebSocket, _connectionFactory.GetType().Name)));
            }

            string requested = WebSocketSettings.SubProtocol;
            string obtained  = ws.SubProtocol;

            if (!(requested == null ? string.IsNullOrWhiteSpace(obtained) : requested.Equals(obtained, StringComparison.OrdinalIgnoreCase)))
            {
                ws.Dispose();
                throw FxTrace.Exception.AsError(new InvalidOperationException(SR.Format(SR.ClientWebSocketFactory_InvalidSubProtocol, _connectionFactory.GetType().Name, obtained, requested)));
            }

            return(ws);
        }
      /// <summary>
      /// Initializes a new instance of the <see cref="MyWebSocket.WebSocketServer"/> class using a preconstructed
      /// settings object.
      /// </summary>
      /// <param name="settings">Settings.</param>
      public WebSocketServerAsync(WebSocketSettings settings)
      {
         this.settings = settings;
         connections = new List<WebSocketConnectionAsync>();
         updateTimer = new System.Timers.Timer();
         updateTimer.Elapsed += ServerUpdate;
         updateTimer.Interval = WebSocketHelper.GCD((long)settings.HandshakeTimeout.TotalMilliseconds,
            (long)settings.PingInterval.TotalMilliseconds);
         updateTimer.Start();

         Log("Server will check connections every " + 
            StringExtensions.LargestTime(TimeSpan.FromMilliseconds(updateTimer.Interval)), 
            LogLevel.Debug);
      }
예제 #6
0
        internal override bool IsMatch(BindingElement b)
        {
            if (!base.IsMatch(b))
            {
                return(false);
            }

            HttpTransportBindingElement http = b as HttpTransportBindingElement;

            if (http == null)
            {
                return(false);
            }

            if (AllowCookies != http.AllowCookies)
            {
                return(false);
            }

            if (AuthenticationScheme != http.AuthenticationScheme)
            {
                return(false);
            }

            if (_decompressionEnabled != http._decompressionEnabled)
            {
                return(false);
            }

            if (_hostNameComparisonMode != http._hostNameComparisonMode)
            {
                return(false);
            }

            if (_inheritBaseAddressSettings != http._inheritBaseAddressSettings)
            {
                return(false);
            }

            if (KeepAliveEnabled != http.KeepAliveEnabled)
            {
                return(false);
            }

            if (_maxBufferSize != http._maxBufferSize)
            {
                return(false);
            }

            if (_method != http._method)
            {
                return(false);
            }

            if (_realm != http._realm)
            {
                return(false);
            }

            if (_transferMode != http._transferMode)
            {
                return(false);
            }

            if (UnsafeConnectionNtlmAuthentication != http.UnsafeConnectionNtlmAuthentication)
            {
                return(false);
            }

            if (_useDefaultWebProxy != http._useDefaultWebProxy)
            {
                return(false);
            }

            if (!WebSocketSettings.Equals(http.WebSocketSettings))
            {
                return(false);
            }

            return(true);
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="MyWebSocket.WebSocketServer"/> class using a preconstructed
 /// settings object.
 /// </summary>
 /// <param name="settings">Settings.</param>
 public WebSocketServer(WebSocketSettings settings) : base("WebSocketServer", settings.ShutdownTimeout)
 {
    this.settings = settings;
    connectionSpinners = new List<WebSocketSpinner>();
    ReportsSpinStatus = true;
 }