Ejemplo n.º 1
0
        public static void BroadcastToOrganization(this WebSocketSharp.Server.WebSocketServiceManager extendedObject,
                                                   Organization organization, JObject jsonMessage)
        {
            lock (_sessionLookup)
            {
                Console.WriteLine(" - Broadcasting to organization #" + organization.Identity);
                Console.WriteLine(" -- sessionLookup key count: " + _sessionLookup.Keys.Count);
                Console.WriteLine(" -- sessionAuthorityLookup key count: " + _sessionAuthorityLookup.Keys.Count);

                foreach (string key in _sessionAuthorityLookup.Keys)
                {
                    if (!_sessionLookup.ContainsKey(key))
                    {
                        Console.WriteLine("INVALID STATE: Authority lookup for " + _sessionAuthorityLookup[key].Person.Canonical + " has no session");
                        continue;
                    }

                    IWebSocketSession session = _sessionLookup[key];
                    if (session.State == WebSocketState.Open) // protect against open/close race condition
                    {
                        if (_sessionAuthorityLookup.ContainsKey(key) &&
                            _sessionAuthorityLookup[key].Organization.Identity == organization.Identity)
                        {
                            session.Context.WebSocket.Send(jsonMessage.ToString());
                        }
                    }
                }
            }
        }
Ejemplo n.º 2
0
        private void init(string hostname, System.Net.IPAddress address, int port, bool secure)
        {
            _hostname = hostname ?? address.ToString();
            _address  = address;
            _port     = port;
            _secure   = secure;

            _authSchemes = AuthenticationSchemes.Anonymous;
            _dnsStyle    = Uri.CheckHostName(hostname) == UriHostNameType.Dns;
            _listener    = new TcpListener(address, port);
            _logger      = new Logger();
            _services    = new WebSocketServiceManager(_logger);
            _sync        = new object();
        }
Ejemplo n.º 3
0
        private void init(
            string hostname, System.Net.IPAddress address, int port, bool secure
            )
        {
            _hostname = hostname;
            _address  = address;
            _port     = port;
            _secure   = secure;

            _docRootPath = "./Public";
            _listener    = createListener(_hostname, _port, _secure);
            _log         = _listener.Log;
            _services    = new WebSocketServiceManager(_log);
            _sync        = new object();
        }
Ejemplo n.º 4
0
        private void init(string hostname, IPAddress address, int port, bool secure)
        {
            this._hostname = hostname ?? HttpServer.convertToString(address);
            this._address  = address;
            this._port     = port;
            this._secure   = secure;
            this._listener = new WebSocketSharp.Net.HttpListener();
            this._listener.Prefixes.Add(string.Format("http{0}://{1}:{2}/", (secure ? "s" : ""), this._hostname, port));
            this._logger   = this._listener.Log;
            this._services = new WebSocketServiceManager(this._logger);
            this._sync     = new object();
            OperatingSystem oSVersion = Environment.OSVersion;

            this._windows = (oSVersion.Platform == PlatformID.Unix ? false : oSVersion.Platform != PlatformID.MacOSX);
        }
Ejemplo n.º 5
0
        private void init(string hostname, System.Net.IPAddress address, int port, bool secure)
        {
            _hostname = hostname ?? convertToString(address);
            _address  = address;
            _port     = port;
            _secure   = secure;

            _listener = new HttpListener();
            _listener.Prefixes.Add(String.Format("http{0}://{1}:{2}/", secure ? "s" : "", _hostname, port));

            _logger   = _listener.Log;
            _services = new WebSocketServiceManager(_logger);
            _sync     = new object();

            _windows = WindowsDriveRegex.IsMatch(Directory.GetDirectoryRoot(Directory.GetCurrentDirectory()));
        }
Ejemplo n.º 6
0
        private void init(string hostname, int port, bool secure)
        {
            _port   = port;
            _secure = secure;

            _listener = new HttpListener();
            _listener.Prefixes.Add(
                String.Format("http{0}://{1}:{2}/", secure ? "s" : "", hostname, port));

            _logger   = _listener.Log;
            _services = new WebSocketServiceManager(_logger);
            _sync     = new object();

            var os = Environment.OSVersion;

            _windows = os.Platform != PlatformID.Unix && os.Platform != PlatformID.MacOSX;
        }
Ejemplo n.º 7
0
        internal void Bind(WebSocketContext context, WebSocketServiceManager sessions)
        {
            if (IsBound)
            {
                return;
            }

            _context   = context;
            _sessions  = sessions;
            _websocket = context.WebSocket;
            _websocket.CookiesValidation = ValidateCookies;
            _websocket.OnOpen           += onOpen;
            _websocket.OnMessage        += onMessage;
            _websocket.OnError          += onError;
            _websocket.OnClose          += onClose;

            IsBound = true;
        }
Ejemplo n.º 8
0
        private void init(
            string hostname, IPAddress address, int port, bool secure
#if SSHARP
            , int maxConnections
#endif
            )
        {
            _hostname       = hostname;
            _address        = address;
            _port           = port;
            _secure         = secure;
            _maxConnections = maxConnections;

            _authSchemes = AuthenticationSchemes.Anonymous;
            _dnsStyle    = Uri.CheckHostName(hostname) == UriHostNameType.Dns;
            _listener    = new TcpListener(_address, _port
#if SSHARP
                                           , _maxConnections
#endif
                                           );
            _log      = new Logger();
            _services = new WebSocketServiceManager(_log);
            _sync     = new object();
        }
Ejemplo n.º 9
0
        public HttpServer(int port, bool secure)
        {
            if (!port.IsPortNumber())
            {
                throw new ArgumentOutOfRangeException("port", "Not between 1 and 65535: " + port);
            }
            if ((port == 80 && secure) || (port == 443 && !secure))
            {
                throw new ArgumentException($"An invalid pair of 'port' and 'secure': {port}, {secure}");
            }
            _port     = port;
            _secure   = secure;
            _listener = new HttpListener();
            _logger   = _listener.Log;
            _services = new WebSocketServiceManager(_logger);
            _state    = ServerState.Ready;
            _sync     = new object();
            OperatingSystem oSVersion = Environment.OSVersion;

            _windows = oSVersion.Platform != PlatformID.Unix && oSVersion.Platform != PlatformID.MacOSX;
            string uriPrefix = string.Format("http{0}://*:{1}/", (!_secure) ? "" : "s", _port);

            _listener.Prefixes.Add(uriPrefix);
        }
Ejemplo n.º 10
0
        internal void Bind(WebSocketContext context, WebSocketServiceManager sessions)
        {
            if (IsBound)
            {
                return;
            }

            if (!ProcessCookies(context.CookieCollection, context.WebSocket.CookieCollection))
            {
                context.WebSocket.Close(HttpStatusCode.BadRequest);
                return;
            }

            _context   = context;
            _sessions  = sessions;
            _websocket = context.WebSocket;

            _websocket.OnOpen    += onOpen;
            _websocket.OnMessage += onMessage;
            _websocket.OnError   += onError;
            _websocket.OnClose   += onClose;

            IsBound = true;
        }
Ejemplo n.º 11
0
 internal WebSocketServiceHost()
 {
     _sessions = new WebSocketServiceManager();
 }
Ejemplo n.º 12
0
 /// <summary>
 /// Initializes a new instance of the WebSocketServiceHost&lt;T&gt; class that listens for incoming connection attempts
 /// on the specified <paramref name="address"/>, <paramref name="port"/>, <paramref name="absPath"/> and <paramref name="secure"/>.
 /// </summary>
 /// <param name="address">
 /// A <see cref="System.Net.IPAddress"/> that contains a local IP address.
 /// </param>
 /// <param name="port">
 /// An <see cref="int"/> that contains a port number.
 /// </param>
 /// <param name="absPath">
 /// A <see cref="string"/> that contains an absolute path.
 /// </param>
 /// <param name="secure">
 /// A <see cref="bool"/> that indicates providing a secure connection or not. (<c>true</c> indicates providing a secure connection.)
 /// </param>
 public WebSocketServiceHost(System.Net.IPAddress address, int port, string absPath, bool secure)
     : base(address, port, absPath, secure)
 {
     _sessions = new WebSocketServiceManager();
 }
 private void init()
 {
     _sessions = new WebSocketServiceManager();
 }
Ejemplo n.º 14
0
 internal WebSocketServiceHost(Logger logger)
     : base(logger)
 {
     _sessions = new WebSocketServiceManager(logger);
 }
Ejemplo n.º 15
0
        internal void Bind(WebSocketContext context, WebSocketServiceManager sessions)
        {
            if (IsBound)
            return;

              _context = context;
              _sessions = sessions;
              _websocket = context.WebSocket;
              _websocket.CookiesValidation = ValidateCookies;
              _websocket.OnOpen += onOpen;
              _websocket.OnMessage += onMessage;
              _websocket.OnError += onError;
              _websocket.OnClose += onClose;

              IsBound = true;
        }
Ejemplo n.º 16
0
 /// <summary>
 /// Initializes a new instance of the WebSocketServiceHost&lt;T&gt; class that listens for incoming connection attempts
 /// on the specified WebSocket URL.
 /// </summary>
 /// <param name="url">
 /// A <see cref="string"/> that contains a WebSocket URL.
 /// </param>
 public WebSocketServiceHost(string url)
     : base(url)
 {
     _sessions = new WebSocketServiceManager();
 }
Ejemplo n.º 17
0
 private bool start(int port)
 {
     try {
         var url = "ws://localhost:" + port.ToString();
         _server = new WebSocketServer(url);
         _serverServiceManager = _server.WebSocketServices;
         _server.AddWebSocketService<Chat>("/chat", () => _serverChatService);
         _server.Start();
         Url = url;
         return true;
     } catch {
     }
     return false;
 }
Ejemplo n.º 18
0
        internal void Bind(WebSocketContext context, WebSocketServiceManager sessions)
        {
            if (IsBound)
            return;

              if (!ProcessCookies(context.CookieCollection, context.WebSocket.CookieCollection))
              {
            context.WebSocket.Close(HttpStatusCode.BadRequest);
            return;
              }

              _context = context;
              _sessions = sessions;
              _websocket = context.WebSocket;

              _websocket.OnOpen    += onOpen;
              _websocket.OnMessage += onMessage;
              _websocket.OnError   += onError;
              _websocket.OnClose   += onClose;

              IsBound = true;
        }