Esempio n. 1
0
 public WebSocketClientChannel(Uri endpointUri, WebSocketConfig config, CancellationToken token)
 {
     endpoint    = endpointUri;
     this.config = config;
     this.token  = token;
     Id          = "ws-" + Guid.NewGuid().ToString();
     sendQueue   = new TaskQueue();
     queue       = new ConcurrentQueue <byte[]>();
 }
Esempio n. 2
0
        public WebSocketServerChannel(HttpContext context, System.Net.WebSockets.WebSocket socket,
                                      WebSocketConfig config, CancellationToken token)
        {
            Id          = "ws-" + Guid.NewGuid();
            this.config = config;
            this.token  = token;

            IsEncrypted     = context.Request.Scheme == "wss";
            IsAuthenticated = context.User.Identity.IsAuthenticated;

            handler            = new WebSocketHandler(config, token);
            handler.OnReceive += Handler_OnReceive;
            handler.OnError   += Handler_OnError;
            handler.OnOpen    += Handler_OnOpen;
            handler.OnClose   += Handler_OnClose;
            this.socket        = socket;
        }
Esempio n. 3
0
        //public WebSocketServerChannel(HttpListenerWebSocketContext context, WebSocketConfig config, CancellationToken token)
        //{
        //    Id = "ws-" + Guid.NewGuid().ToString();
        //    this.token = token;
        //    this.IsEncrypted = context.RequestUri.Scheme == "wss";
        //    this.IsAuthenticated = HttpHelper.HttpContext.User.Identity.IsAuthenticated;
        //    this.handler = new WebSocketHandler(config, token);
        //    this.handler.OnReceive += Handler_OnReceive;
        //    this.handler.OnError += Handler_OnError;
        //    this.handler.OnOpen += Handler_OnOpen;
        //    this.handler.OnClose += Handler_OnClose;
        //}



        public WebSocketServerChannel(HttpContext context, WebSocketConfig config, CancellationToken token)
        {
            Id                   = "ws-" + Guid.NewGuid().ToString();
            this.config          = config;
            this.token           = token;
            this.IsEncrypted     = context.Request.Scheme == "wss";
            this.IsAuthenticated = context.User.Identity.IsAuthenticated;

            this.handler            = new WebSocketHandler(config, token);
            this.handler.OnReceive += Handler_OnReceive;
            this.handler.OnError   += Handler_OnError;
            this.handler.OnOpen    += Handler_OnOpen;
            this.handler.OnClose   += Handler_OnClose;

            Task task = Task.Factory.StartNew(async() =>
            {
                await Task.Delay(100);
                this.socket = await context.AcceptWebSocketRequestAsync(this.handler);
            });

            Task.WhenAll(task);
        }
Esempio n. 4
0
 public static WebSocketChannel Create(Uri endpointUri, X509Certificate2 certificate, string subProtocol, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketClientChannel(endpointUri, certificate, subProtocol, config, token));
 }
Esempio n. 5
0
 public static WebSocketChannel Create(Uri endpointUri, string securityToken, string subProtocol, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketClientChannel(endpointUri, securityToken, subProtocol, config, token));
 }
Esempio n. 6
0
 public static WebSocketChannel Create(Uri endpointUri, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketClientChannel(endpointUri, config, token));
 }
Esempio n. 7
0
 public static WebSocketChannel Create(HttpContext context, System.Net.WebSockets.WebSocket socket, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketServerChannel(context, socket, config, token));
 }
Esempio n. 8
0
 public WebSocketHandler(WebSocketConfig config, CancellationToken token)
 {
     this.config = config;
     this.token  = token;
 }
Esempio n. 9
0
 public WebSocketClientChannel(Uri endpointUri, X509Certificate2 certificate, string subProtocol, WebSocketConfig config, CancellationToken token)
 {
     endpoint         = endpointUri;
     this.certificate = certificate;
     this.subProtocol = subProtocol;
     this.config      = config;
     this.token       = token;
     Id        = "ws-" + Guid.NewGuid().ToString();
     sendQueue = new TaskQueue();
     queue     = new ConcurrentQueue <byte[]>();
 }