Beispiel #1
0
        private void Upgrade(Reactor.Http.HttpContext context, Reactor.Action <Exception, Reactor.Web.Socket.Socket> callback)
        {
            var request = ServerWebSocketUpgradeRequest.Create(context);

            //--------------------------------------------------------
            // if not a web socket attempt, defer to http callback.
            //--------------------------------------------------------

            if (request == null)
            {
                this.servercb(context);

                return;
            }

            var response = ServerWebSocketUpgradeResponse.Create(request);

            var socket_context = new Reactor.Web.Socket.Context(context);

            this.OnUpgrade(socket_context, (success, reason) => {
                if (!success)
                {
                    response.Reject(reason == null ? "" : reason, (exception) => callback(exception, null));

                    return;
                }

                response.Accept((exception) => {
                    if (exception != null)
                    {
                        callback(exception, null);

                        return;
                    }

                    var channel = new Transport(context.Connection);

                    var socket = new Socket(channel);

                    socket.Context = socket_context;

                    callback(null, socket);
                });
            });
        }
Beispiel #2
0
        private void Upgrade(Reactor.Http.HttpContext context, Reactor.Action<Exception, Reactor.Web.Socket.Socket> callback)
        {
            var request = ServerWebSocketUpgradeRequest.Create(context);

            //--------------------------------------------------------
            // if not a web socket attempt, defer to http callback.
            //--------------------------------------------------------

            if (request == null) {

                this.servercb(context);

                return;
            }

            var response       = ServerWebSocketUpgradeResponse.Create(request);

            var socket_context = new Reactor.Web.Socket.Context(context);

            this.OnUpgrade(socket_context, (success, reason) => {

                if (!success) {

                    response.Reject(reason == null ? "" : reason, (exception) => callback(exception, null));

                    return;
                }

                response.Accept((exception) => {

                    if(exception != null) {

                        callback(exception, null);

                        return;
                    }

                    var channel = new Transport(context.Connection);

                    var socket  = new Socket(channel);

                    socket.Context = socket_context;

                    callback(null, socket);
                });
            });
        }