Пример #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[]>();
 }
Пример #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;
        }
Пример #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);
        }
Пример #4
0
 public static WebSocketChannel Create(Uri endpointUri, X509Certificate2 certificate, string subProtocol, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketClientChannel(endpointUri, certificate, subProtocol, config, token));
 }
Пример #5
0
 public static WebSocketChannel Create(Uri endpointUri, string securityToken, string subProtocol, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketClientChannel(endpointUri, securityToken, subProtocol, config, token));
 }
Пример #6
0
 public static WebSocketChannel Create(Uri endpointUri, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketClientChannel(endpointUri, config, token));
 }
Пример #7
0
 public static WebSocketChannel Create(HttpContext context, System.Net.WebSockets.WebSocket socket, WebSocketConfig config, CancellationToken token)
 {
     return(new WebSocketServerChannel(context, socket, config, token));
 }
Пример #8
0
 public WebSocketHandler(WebSocketConfig config, CancellationToken token)
 {
     this.config = config;
     this.token  = token;
 }
Пример #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[]>();
 }