public WebSocketServer(string location)
        {
            var uri = new Uri(location);

            Port        = uri.Port;
            Location    = location;
            _locationIP = ParseIPAddress(uri);
            _scheme     = uri.Scheme;
            var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);

            if (!MonoHelper.IsRunningOnMono())
            {
#if __MonoCS__
#else
#if !NET45
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
                {
                    socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
                }
#if !NET45
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                }
#endif
#endif
            }
            ListenerSocket        = new SocketWrapper(socket);
            SupportedSubProtocols = new string[0];
        }
Exemple #2
0
 private void ListenForClients()
 {
     ListenerSocket.Accept(
         OnClientConnect,
         e => {
         FleckLog.Error("Listener socket is closed", e);
         if (RestartAfterListenError)
         {
             FleckLog.Info("Listener socket restarting");
             try
             {
                 ListenerSocket.Dispose();
                 var socket     = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);
                 ListenerSocket = new SocketWrapper(socket);
                 Start(_config);
                 FleckLog.Info("Listener socket restarted");
             }
             catch (Exception ex)
             {
                 FleckLog.Error("Listener could not be restarted", ex);
             }
         }
     }
         );
 }
Exemple #3
0
        public WebSocketServer(string location, bool supportDualStack = true)
        {
            var uri = new Uri(location);

            Port             = uri.Port;
            Location         = location;
            SupportDualStack = supportDualStack;

            _locationIP = ParseIPAddress(uri);
            _scheme     = uri.Scheme;
            var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);

            socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);

            if (SupportDualStack)
            {
                if (!FleckRuntime.IsRunningOnMono() && FleckRuntime.IsRunningOnWindows())
                {
                    socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
                }
            }

            ListenerSocket        = new SocketWrapper(socket);
            SupportedSubProtocols = new string[0];
        }
Exemple #4
0
 public SocketWrapper(SocketWrapper listeningSocket)
 {
     _tokenSource     = new CancellationTokenSource();
     _taskFactory     = new TaskFactory(_tokenSource.Token);
     _socket          = listeningSocket._socket;
     _stream          = _socket.OutputStream;
     _listeningSocket = listeningSocket._listeningSocket;
 }
Exemple #5
0
        public PolicyServer(IPAddress ipAddress, int port = 843)         // 843 is standard port for policy servers
        {
            _ipEndPoint = new IPEndPoint(ipAddress, port);

            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            ListenerSocket = new SocketWrapper(socket);
        }
Exemple #6
0
 public WebSocketServer(int port, string location)
 {
     var uri = new Uri(location);
     Port = uri.Port > 0 ? uri.Port : port;
     Location = location;
     _scheme = uri.Scheme;
     var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
     ListenerSocket = new SocketWrapper(socket);
 }
 public WebSocketServer(int port, string location)
 {
     var uri = new Uri(location);
     Port = uri.Port > 0 ? uri.Port : port;
     Location = uri.Host;
     _scheme = uri.Scheme;
        _socket = new StreamSocketListener();
     ListenerSocket = new SocketWrapper(_socket);
     SupportedSubProtocols = new string[0];
 }
        public WebSocketServer(int port, string location)
        {
            var uri = new Uri(location);

            Port     = uri.Port > 0 && uri.OriginalString.IndexOf(uri.Port.ToString()) >= 0 ? uri.Port : port;
            Location = location;
            _scheme  = uri.Scheme;
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            ListenerSocket = new SocketWrapper(socket);
        }
        public WebSocketServer(int port, string location)
        {
            var uri = new Uri(location);

            Port                  = uri.Port > 0 ? uri.Port : port;
            Location              = uri.Host;
            _scheme               = uri.Scheme;
            _socket               = new StreamSocketListener();
            ListenerSocket        = new SocketWrapper(_socket);
            SupportedSubProtocols = new string[0];
        }
Exemple #10
0
        public WebSocketServer(int port, string location)
        {
            var uri = new Uri(location);

            Port     = uri.Port > 0 ? uri.Port : port;
            Location = location;
            _scheme  = uri.Scheme;
            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);

            ListenerSocket        = new SocketWrapper(socket);
            SupportedSubProtocols = new string[0];
        }
Exemple #11
0
 private void TryRestart()
 {
     FleckLog.Info("Listener socket restarting");
     try {
         ListenerSocket.Dispose();
         var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);
         ListenerSocket = new SocketWrapper(socket);
         Start(_config);
         FleckLog.Info("Listener socket restarted");
     } catch (Exception ex) {
         FleckLog.Error("Listener socket could not be restarted", ex);
     }
 }
Exemple #12
0
 public WebSocketServer(int port, string location)
 {
     var uri = new Uri(location);
     Port = uri.Port > 0 ? uri.Port : port;
     Location = location;
     _locationIP = ParseIPAddress(uri);
     _scheme = uri.Scheme;
     var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);
     if(!MonoHelper.IsRunningOnMono()){
           #if __MonoCS__
           #else
             socket.SetSocketOption(SocketOptionLevel.IP, SocketOptionName.IPOptions, true);
           #endif
     }
     ListenerSocket = new SocketWrapper(socket);
     SupportedSubProtocols = new string[0];
 }
Exemple #13
0
        public WebSocketServer(int port, string location)
        {
            var uri = new Uri(location);

            Port        = uri.Port > 0 ? uri.Port : port;
            Location    = location;
            _locationIP = ParseIPAddress(uri);
            _scheme     = uri.Scheme;
            var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);

            if (!MonoHelper.IsRunningOnMono())
            {
                  #if __MonoCS__
                  #else
                socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.IPv6Only, false);
                  #endif
            }
            ListenerSocket        = new SocketWrapper(socket);
            SupportedSubProtocols = new string[0];
        }
Exemple #14
0
        private static void SocketAcceptAsyncCallback(
            IAsyncResult asynResult
            )
        {
            var _state = asynResult.AsyncState as SocketAsyncState <ISocket, Socket>;

            try
            {
                if (_state._CancelSource.IsCancellationRequested)
                {
                    _state._Callback(null);
                }
                else
                {
                    var _socketWrap = new SocketWrapper(_state._SocketOrStream.EndAccept(asynResult));
                    _state._Callback(_socketWrap);
                }
            }
            catch (Exception ex)
            {
                _state._Error(ex);
            }
        }
Exemple #15
0
        public WebSocketServer(string location)
        {
            var uri = new Uri(location);

            Port        = uri.Port;
            Location    = location;
            _locationIP = ParseIPAddress(uri);
            _scheme     = uri.Scheme;
            var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);

            if (!MonoHelper.IsRunningOnMono())
            {
#if __MonoCS__
#else
#if !NET45
                if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
#endif
                {
                    //https://docs.microsoft.com/zh-cn/dotnet/api/system.net.sockets.socketoptionname?view=netframework-4.7.2
                    //socket.SetSocketOption(
                    //		SocketOptionLevel.IPv6,
                    //		SocketOptionName.KeepAlive,//SocketOptionName.IPv6Only,
                    //		false
                    //	);
                }
#if !NET45
                if (!RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
                {
                    socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReuseAddress, 1);
                }
#endif
#endif
            }
            ListenerSocket        = new SocketWrapper(socket);
            SupportedSubProtocols = new string[0];
        }
Exemple #16
0
 private void ListenForClients()
 {
     ListenerSocket.Accept(OnClientConnect, e => {
         FleckLog.Error("Listener socket is closed", e);
         if(RestartAfterListenError){
             FleckLog.Info("Listener socket restarting");
             try
             {
                 ListenerSocket.Dispose();
                 var socket = new Socket(_locationIP.AddressFamily, SocketType.Stream, ProtocolType.IP);
                 ListenerSocket = new SocketWrapper(socket);
                 Start(_config);
                 FleckLog.Info("Listener socket restarted");
             }
             catch (Exception ex)
             {
                 FleckLog.Error("Listener could not be restarted", ex);
             }
         }
     });
 }
Exemple #17
-1
        // 843 is standard port for policy servers
        public PolicyServer(IPAddress ipAddress, int port = 843)
        {
            _ipEndPoint = new IPEndPoint(ipAddress, port);

            var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
            ListenerSocket = new SocketWrapper(socket);
        }
Exemple #18
-1
 public WebSocketServer(int port, string location)
 {
     Port = port;
     Location = location;
     var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
     ListenerSocket = new SocketWrapper(socket);
 }
 public SocketWrapper(SocketWrapper listeningSocket)
 {
     _tokenSource = new CancellationTokenSource();
     _taskFactory = new TaskFactory(_tokenSource.Token);
     _socket = listeningSocket._socket;
     _stream = _socket.OutputStream;
     _listeningSocket = listeningSocket._listeningSocket;
 }
Exemple #20
-1
 public SimpleServer(int port)
 {
     Port = port;
     var socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.IP);
     ListenerSocket = new SocketWrapper(socket);
 }