예제 #1
0
        static void Main(string[] args)
        {
            var handler = new HttpHandler();
            handler.AddStatic("^/$", "./www/index.html");
            handler.AddStatic("^/script/(.*)$", "./www/script/{1}");
            handler.AddStatic("^/file/(.*)$", "./www/test/file/{1}");

            handler.AddDynamic("^/test.web$", TestModule.TestController.TestMain);
            handler.AddWebSocket("^/echo$", strings => new WebSocketHandler());
            handler.AddJSON("^/test.json$", strings =>
                                                {
                                                    dynamic json = new JObject();
                                                    json.test = "abcd";
                                                    json.test2 = 123;
                                                    json.a = new JArray(strings);
                                                    return json;
                                                });
            var io = new SocketIO();
            io.On("connection", s =>
                                    {
                                        var socket = s as ISocketIO;
                                        socket.Emit("news", new JArray(JsonConvert.DeserializeObject("{ hello: 'world' }")));
                                        socket.On("my other event", array => System.Console.WriteLine(array[0].my));
                                    });
            handler.AddSocketIO(io);

            var netronics = new Netronics.Netronics(new HttpProperties(() => handler));
            netronics.Start();
            ExitEvent.WaitOne();
        }
예제 #2
0
        public void Test3()
        {
            var handler = new HttpHandler();
            handler.AddStatic("/$", "./www/index.html");
            handler.AddStatic("^/file/(.*)$", "./www/test/file/{1}");

            handler.AddDynamic("/test.web", TestAction);
            var netronics = new Netronics.Netronics(new HttpProperties(() => handler, 7777));
            netronics.Start();
            ExitEvent.WaitOne();
        }
예제 #3
0
        public void Test2()
        {
            var handler = new HttpHandler();
            handler.AddStatic("/file/(*)","./www/file/{0}");/*
            handler.AddDynamic("/test.web", requestData =>
                                                {
                                                    return new Response();
                                                });*/

            var netronics = new Netronics.Netronics(new HttpProperties(() => handler, 8888));
            netronics.Start();
            var request = WebRequest.Create("http://127.0.0.1:8888/a?b=c");
            request.GetResponse();
            netronics.Stop();
        }
예제 #4
0
        static void Main(string[] args)
        {
            AppDomain.CurrentDomain.UnhandledException += (s, e) =>
            {
            };

            var handler = new HttpHandler();
            handler.AddStatic("^/$", "./www/index.html");
            handler.AddStatic("^(.*).css$", "./www/{1}.css");
            handler.AddStatic("^/script/(.*)$", "./www/script/{1}");
            handler.AddStatic("^/file/(.*)$", "./www/test/file/{1}");

            handler.AddDynamic("^/test.web$", TestModule.TestController.TestMain);
            handler.AddWebSocket("^/echo$", strings => new WebSocketHandler());
            handler.AddJSON("^/test.json$", strings =>
                                                {
                                                    dynamic json = new JObject();
                                                    json.test = "abcd";
                                                    json.test2 = 123;
                                                    json.a = new JArray(strings);
                                                    return json;
                                                });
            var io = new SocketIO();
            io.On("connection", s =>
                                    {
                                        var socket = s as ISocketIO;
                                        lock (UserList)
                                        {
                                            UserList.Add(socket);

                                            dynamic obj = new JObject();
                                            obj.name = "System";
                                            obj.msg = socket.ToString() + " 접속";
                                            foreach (var sock in UserList)
                                            {
                                                sock.Emit("chat", new JArray(new object[] { obj }));
                                            }
                                        }

                                        socket.On("chat", o =>
                                                              {
                                                                  dynamic obj = new JObject();
                                                                  obj.name = socket.ToString();
                                                                  obj.msg = o[0].msg;
                                                                  lock (UserList)
                                                                  {
                                                                      foreach (var sock in UserList)
                                                                      {
                                                                          sock.Emit("chat", new JArray(new object[] { obj }));
                                                                      }
                                                                  }
                                                              });
                                    });
            io.On("disconnect", o =>
                                    {
                                        var socket = o as ISocketIO;
                                        lock (UserList)
                                        {
                                            UserList.Remove(socket);

                                            dynamic obj = new JObject();
                                            obj.name = "System";
                                            obj.msg = socket.ToString() + " 접속 종료";
                                            foreach (var sock in UserList)
                                            {
                                                sock.Emit("chat", new JArray(new object[] { obj }));
                                            }
                                        }
                                    });
            handler.AddSocketIO(io);

            var netronics = new Netronics.Netronics(new HttpsProperties(() => handler));
            netronics.Start();
            ExitEvent.WaitOne();
        }