Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="socket"></param>
        /// <param name="receiver"></param>
        public static void BindSocketReceiver(WebSocket socket, WebSocketReceiver receiver)
        {
            if (socket == null)
            {
                throw new ArgumentNullException(nameof(socket));
            }

            if (receiver == null)
            {
                throw new ArgumentNullException(nameof(receiver));
            }

            _receivers.TryAdd(socket, receiver);
        }
        /// <inheritdoc />
        public bool Register(ISocketCacheKey key, EventHandler <MessageReceiveEventArgs> handler)
        {
            if (handler == null)
            {
                throw new ArgumentNullException(nameof(handler));
            }

            var socket = _socketManager.Get(key);

            if (socket == null)
            {
                return(false);
            }

            var receiver = WebSocketReceiver.GetReceiver(socket);

            if (receiver == null)
            {
                return(false);
            }
            receiver.MessageHandler += handler;
            return(true);
        }