Beispiel #1
0
        public static IHandler Create(WebSocketHttpRequest request, Action <string> onMessage, Action onClose)
        {
            var readState = new ReadState();

            return(new ComposableHandler
            {
                Handshake = () => Hybi13Handler.BuildHandshake(request),
                Frame = s => Hybi13Handler.FrameData(Encoding.UTF8.GetBytes(s), FrameType.Text),
                Close = i => Hybi13Handler.FrameData(i.ToBigEndianBytes <ushort>(), FrameType.Close),
                ReceiveData = d => Hybi13Handler.ReceiveData(d, readState, (op, data) => Hybi13Handler.ProcessFrame(op, data, onMessage, onClose))
            });
        }
Beispiel #2
0
        public static IHandler Create(WebSocketHttpRequest request, Action <string> onMessage, Action onClose, Action <byte[]> onBinary, Action <byte[]> onPing, Action <byte[]> onPong)
        {
            var readState = new ReadState();

            return(new ComposableHandler
            {
                Handshake = sub => Hybi13Handler.BuildHandshake(request, sub),
                TextFrame = s => Hybi13Handler.FrameData(Encoding.UTF8.GetBytes(s), FrameType.Text),
                BinaryFrame = s => Hybi13Handler.FrameData(s, FrameType.Binary),
                PingFrame = s => Hybi13Handler.FrameData(s, FrameType.Ping),
                PongFrame = s => Hybi13Handler.FrameData(s, FrameType.Pong),
                CloseFrame = i => Hybi13Handler.FrameData(IntExtensions.ToBigEndianBytes <ushort>(i), FrameType.Close),
                ReceiveData = d => Hybi13Handler.ReceiveData(d, readState, (op, data) => Hybi13Handler.ProcessFrame(op, data, onMessage, onClose, onBinary, onPing, onPong))
            });
        }