Exemple #1
0
        protected virtual async Task HandleAcceptedTcp(TcpClient tcpClient)
        {
            EPPair         epPair     = new EPPair();
            HttpConnection connection = null;

            try {
                epPair = EPPair.FromSocket(tcpClient.Client);
                var myStream = MyStream.FromSocket(tcpClient.Client);
                var stream   = myStream.ToStream();
                connection = this.CreateHttpConnectionObject(tcpClient, stream, epPair);
                if (connection == null)
                {
                    try {
                        tcpClient.Close();
                    } catch (Exception) { }
                    return;
                }
            } catch (Exception e) {
                Logger.exception(e, Logging.Level.Error, $"({epPair}) httpConnection creating");
                return;
            }
            try {
                await connection.Process();
            } catch (Exception e) {
                try {
                    this.OnHttpConnectionException(e, connection);
                } catch (Exception e2) {
                    Logger.exception(e2, Logging.Level.Error, "In OnHttpConnectionExceptionExit");
                }
            }
        }
Exemple #2
0
        public static async Task <WebSocketClient> ConnectToAsync(AddrPort dest, string path,
                                                                  int timeout, CancellationToken ct)
        {
            Socket socket = await NaiveUtils.ConnectTcpAsync(dest, timeout, async x => x, ct);

            try {
                var socketStream = MyStream.FromSocket(socket);
                var ws           = new WebSocketClient(MyStream.ToStream(socketStream), path);
                ws.Host = dest.Host;
                return(ws);
            } catch (Exception) {
                socket.Dispose();
                throw;
            }
        }