示例#1
0
        public SocketWrapper(Socket socket)
        {
            _tokenSource = new CancellationTokenSource();
            _taskFactory = new TaskFactory(_tokenSource.Token);
            _socket      = socket;
            if (_socket.Connected)
            {
                _stream = new NetworkStream(_socket);
            }

            // The tcp keepalive default values on most systems
            // are huge (~7200s). Set them to something more reasonable.
            if (MDSRuntime.IsRunningOnWindows())
            {
                SetKeepAlive(socket, KeepAliveInterval, RetryInterval);
            }
        }
示例#2
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);

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

            ListenerSocket        = new SocketWrapper(socket);
            SupportedSubProtocols = new string[0];
        }