Пример #1
0
        public override AChannel ConnectChannel(string address)
        {
            ClientWebSocket webSocket = new ClientWebSocket();
            WChannel        channel   = new WChannel(webSocket, this);

            channels[channel.Id] = channel;
            channel.ConnectAsync(address);
            return(channel);
        }
Пример #2
0
        public async void StartAccept(IEnumerable <string> prefixs)
        {
            try
            {
                foreach (string prefix in prefixs)
                {
                    httpListener.Prefixes.Add(prefix);
                }

                httpListener.Start();

                while (true)
                {
                    try
                    {
                        HttpListenerContext httpListenerContext = await httpListener.GetContextAsync();

                        HttpListenerWebSocketContext webSocketContext = await httpListenerContext.AcceptWebSocketAsync(null);

                        WChannel channel = new WChannel(webSocketContext, this);

                        channels[channel.Id] = channel;

                        OnAccept(channel);
                    }
                    catch (Exception e)
                    {
                        Log.Error(e);
                    }
                }
            }
            catch (HttpListenerException e)
            {
                if (e.ErrorCode == 5)
                {
                    throw new Exception($"CMD管理员中输入: netsh http add urlacl url=http://*:8080/ user=Everyone", e);
                }

                Log.Error(e);
            }
            catch (Exception e)
            {
                Log.Error(e);
            }
        }