Exemplo n.º 1
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpSocketServer"/> class.
        /// </summary>
        /// <param name="port">The port.</param>
        /// <param name="endpointInfo">The web server's endpoint information.</param>
        /// <param name="endpointParameters">The web server's endpoint parameters.</param>
        /// <param name="details">The web server's details.</param>
        public EtpSelfHostedWebServer(int port, EtpEndpointInfo endpointInfo, EtpEndpointParameters endpointParameters = null, EtpWebServerDetails details = null)
        {
            Logger = LogManager.GetLogger(GetType());

            Details       = details ?? new EtpWebServerDetails();
            ServerManager = new EtpServerManager(Details, endpointInfo, endpointParameters);

            Uri = new Uri($"http://localhost:{port}");
        }
Exemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpSelfHostedWebServer"/> class.
        /// </summary>
        /// <param name="port">The port.</param>
        /// <param name="endpointInfo">The web server's endpoint information.</param>
        /// <param name="endpointParameters">The web server's endpoint parameters.</param>
        /// <param name="details">The web server's details.</param>
        public EtpSelfHostedWebServer(int port, EtpEndpointInfo endpointInfo, EtpEndpointParameters endpointParameters = null, EtpWebServerDetails details = null)
        {
            Logger = LogManager.GetLogger(GetType());

            Details       = details ?? new EtpWebServerDetails();
            ServerManager = new EtpServerManager(Details, endpointInfo, endpointParameters);

            _server = new WebSocketServer(Details.SupportedVersions.Select(v => new BasicSubProtocol(EtpFactory.GetSubProtocol(v))));

            _server.Setup(new ServerConfig
            {
                Ip               = "Any",
                Port             = port,
                MaxRequestLength = int.MaxValue,
            });

            _server.NewSessionConnected += OnNewSessionConnected;
            _server.NewDataReceived     += OnNewDataReceived;
            _server.SessionClosed       += OnSessionClosed;

            Uri = new Uri($"http://localhost:{port}");
        }
Exemplo n.º 3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpSessionNativeBase"/> class.
 /// </summary>
 /// <param name="webSocket">The web socket.</param>
 /// <param name="etpVersion">The ETP version.</param>
 /// <param name="encoding">The ETP encoding for the session.</param>
 /// <param name="info">The endpoint's information.</param>
 /// <param name="parameters">The endpoint's parameters.</param>
 /// <param name="headers">The WebSocket or HTTP headers.</param>
 /// <param name="isClient">Whether or not this is the client-side of the session.</param>
 /// <param name="sessionId">The session ID if this is a server.</param>
 public EtpSessionNativeBase(EtpVersion etpVersion, EtpEncoding encoding, WebSocket webSocket, EtpEndpointInfo info, EtpEndpointParameters parameters, IDictionary <string, string> headers, bool isClient, string sessionId)
     : base(etpVersion, encoding, info, parameters, headers, isClient, sessionId, !isClient)
 {
     Socket = webSocket;
 }
Exemplo n.º 4
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpClient"/> class.
        /// </summary>
        /// <param name="uri">The ETP server URI.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="info">The client's information.</param>
        /// <param name="parameters">The client's parameters.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="headers">The WebSocket headers.</param>
        public EtpClient(string uri, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters = null, Security.Authorization authorization = null, IDictionary <string, string> headers = null)
            : base(etpVersion, encoding, new ClientWebSocket(), info, parameters, headers, true, null)
        {
            Headers.SetAuthorization(authorization);

            ClientSocket.Options.AddSubProtocol(EtpFactory.GetSubProtocol(EtpVersion));

            foreach (var item in Headers)
            {
                ClientSocket.Options.SetRequestHeader(item.Key, item.Value);
            }

            Uri = new Uri(uri);

            // NOTE: User-Agent cannot be set on a .NET Framework ClientWebSocket:
            // https://github.com/dotnet/corefx/issues/26627
        }
Exemplo n.º 5
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpServerManager"/> class.
 /// </summary>
 /// <param name="webServerDetails">The web server details.</param>
 /// <param name="endpointInfo">The server manager's endpoint information.</param>
 /// <param name="endpointParameters">The server manager's endpoint parameters.</param>
 public EtpServerManager(EtpWebServerDetails webServerDetails, EtpEndpointInfo endpointInfo, EtpEndpointParameters endpointParameters = null)
     : base(webServerDetails, endpointInfo, endpointParameters)
 {
 }
Exemplo n.º 6
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpServer"/> class.
 /// </summary>
 /// <param name="webSocket">The web socket.</param>
 /// <param name="etpVersion">The ETP version for the session.</param>
 /// <param name="encoding">The ETP encoding for the session.</param>
 /// <param name="info">The server's information.</param>
 /// <param name="parameters">The server's parameters.</param>
 /// <param name="headers">The WebSocket or HTTP headers.</param>
 public EtpServer(EtpServerWebSocket webSocket, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters = null, IDictionary <string, string> headers = null)
     : base(etpVersion, encoding, info, parameters, headers, false, webSocket.WebSocketSession.SessionID, false)
 {
     _webSocket = webSocket;
     _session   = _webSocket.WebSocketSession;
     _session.SocketSession.Closed += OnSocketSessionClosed;
 }
Exemplo n.º 7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="EtpServer"/> class.
 /// </summary>
 /// <param name="webSocket">The web socket.</param>
 /// <param name="etpVersion">The ETP version for the session.</param>
 /// <param name="encoding">The ETP encoding for the session.</param>
 /// <param name="info">The server's information.</param>
 /// <param name="parameters">The server's parameters.</param>
 /// <param name="headers">The WebSocket or HTTP headers.</param>
 public EtpServer(WebSocket webSocket, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters = null, IDictionary <string, string> headers = null)
     : base(etpVersion, encoding, webSocket, info, parameters, headers, false, Guid.NewGuid().ToString())
 {
 }
Exemplo n.º 8
0
        /// <summary>
        /// Initializes a new instance of the <see cref="EtpClient"/> class.
        /// </summary>
        /// <param name="uri">The ETP server URI.</param>
        /// <param name="etpVersion">The ETP version for the session.</param>
        /// <param name="encoding">The ETP encoding for the session.</param>
        /// <param name="info">The client's information.</param>
        /// <param name="parameters">The client's parameters.</param>
        /// <param name="authorization">The client's authorization details.</param>
        /// <param name="headers">The WebSocket headers.</param>
        public EtpClient(string uri, EtpVersion etpVersion, EtpEncoding encoding, EtpEndpointInfo info, EtpEndpointParameters parameters, Security.Authorization authorization = null, IDictionary <string, string> headers = null)
            : base(etpVersion, encoding, info, parameters, headers, true, null, false)
        {
            Headers.SetAuthorization(authorization);

            _socket = new W4N.WebSocket(uri,
                                        subProtocol: EtpFactory.GetSubProtocol(EtpVersion),
                                        cookies: null,
                                        customHeaderItems: Headers.ToList(),
                                        userAgent: info.ApplicationName);
        }