示例#1
0
        public Server Listen(int port, Reactor.Action <Exception> callback)
        {
            try {
                this.httplistener = new Reactor.Net.HttpListener();

                this.httplistener.Prefixes.Add(string.Format("http://*:{0}/", port));

                this.httplistener.Start();

                this.GetContext();

                callback(null);
            }
            catch (Exception exception) {
                if (exception is HttpListenerException)
                {
                    callback(exception);
                }
                else
                {
                    callback(exception);
                }
            }

            return(this);
        }
示例#2
0
        public static void GetContext(Reactor.Net.HttpListener listener, Action <Exception, Reactor.Net.HttpListenerContext> callback)
        {
            try
            {
                listener.BeginGetContext((result) =>
                {
                    try
                    {
                        var context = listener.EndGetContext(result);

                        Loop.Post(() =>
                        {
                            callback(null, context);
                        });
                    }
                    catch (Exception exception)
                    {
                        Loop.Post(() =>
                        {
                            callback(exception, null);
                        });
                    }
                }, null);
            }
            catch (Exception exception)
            {
                callback(exception, null);
            }
        }
示例#3
0
        public Server Listen(int port, Reactor.Action<Exception> callback)
        {
            try {

                this.httplistener = new Reactor.Net.HttpListener();

                this.httplistener.Prefixes.Add(string.Format("http://*:{0}/", port));

                this.httplistener.Start();

                this.GetContext();

                callback(null);
            }
            catch(Exception exception) {

                if(exception is HttpListenerException) {

                    callback(exception);
                }
                else {

                    callback(exception);
                }
            }

            return this;
        }