Ejemplo n.º 1
0
        public static void Init()
        {
            new Thread(new ThreadStart(() =>
            {
                TcpProxyConfiguration config = new TcpProxyConfiguration()
                {
                    PublicHost    = new Host(IPAddress.Parse("0.0.0.0"), Port),
                    HttpHost      = new Host(IPAddress.Loopback, portHTTP),
                    WebSocketHost = new Host(IPAddress.Loopback, portWebSocket),
                };

                var httpHost = new HttpProxyServer();
                var wsServer = new WebSocketServer(string.Format("ws://0.0.0.0:{0}", portWebSocket));
                var tcpProxy = new TcpProxyServer(config);

                wsServer.Start(client =>
                {
                    client.OnOpen    = () => { try { MsgSocket.OnOpen(client); } catch { } };
                    client.OnClose   = () => { try { MsgSocket.OnClose(client); } catch { } };
                    client.OnMessage = msg => { try { MsgSocket.OnMessage(client, msg); } catch { } };
                    client.OnBinary  = rawData => { try { MsgSocket.OnBinary(client, rawData); } catch { } };
                    client.OnError   = ex => { try { MsgSocket.OnError(client, ex); } catch { } };
                });

                httpHost.Start(portHTTP);
                //httpHost.Start(string.Format("http://localhost:{0}/", portHTTP));

                tcpProxy.Start();

                while (true)
                {
                }
            })).Start();
        }
Ejemplo n.º 2
0
        public void Start()
        {
            TcpProxyConfiguration config = new TcpProxyConfiguration()
            {
                PublicHost    = new Host(IPAddress.Parse("0.0.0.0"), Port),
                HttpHost      = new Host(IPAddress.Loopback, PortHTTP),
                WebSocketHost = new Host(IPAddress.Loopback, PortWebSocket),
            };

            var httpHost = new HttpProxyServer();
            var wsServer = new WebSocketServer(string.Format("ws://0.0.0.0:{0}", PortWebSocket));
            var tcpProxy = new TcpProxyServer(config);

            wsServer.Start(connect =>
            {
                connect.OnOpen  = () => { try { host.OnOpen(connect); } catch { } };
                connect.OnClose = () => { try { host.OnClose(connect.ConnectionInfo.Id); } catch { } };
                //connect.OnMessage = msg => { try { OnMessage(connect, msg); } catch { } };
                connect.OnBinary = rawData => { try { host.OnReceiveBinary(rawData); } catch { } };
                //connect.OnError = ex => { try { OnError(connect, ex); } catch { } };
            });

            httpHost.Start(PortHTTP);
            //httpHost.Start(string.Format("http://localhost:{0}/", portHTTP));

            tcpProxy.Start();
        }
Ejemplo n.º 3
0
        static void Main(string[] args)
        {
            TcpProxyConfiguration configuration = new TcpProxyConfiguration()
            {
                PublicHost = new Host()
                {
                    IpAddress = IPAddress.Parse("0.0.0.0"),
                    Port = 8080
                },
                HttpHost = new Host()
                {
                    IpAddress = IPAddress.Loopback,
                    Port = 8081
                },
                WebSocketHost = new Host()
                {

                    IpAddress = IPAddress.Loopback,
                    Port = 8082
                }
            };

            using (var nancyHost = new NancyHost(new Uri("http://localhost:8081")))
            using (var websocketServer = new WebSocketServer("ws://0.0.0.0:8082"))
            using (var tcpProxy = new TcpProxyServer(configuration))
            {
                nancyHost.Start();
                websocketServer.Start(connection =>
                {
                    connection.OnOpen = () => Console.WriteLine("COnnection on open");
                    connection.OnClose = () => Console.WriteLine("Connection on close");
                    connection.OnMessage = message => Console.WriteLine("Message: " + message);
                });

                tcpProxy.Start();

                Console.WriteLine("Press [Enter] to stop");
                Console.ReadLine();
            }
        }
Ejemplo n.º 4
0
        static void Main(string[] args)
        {
            TcpProxyConfiguration configuration = new TcpProxyConfiguration()
            {
                PublicHost = new Host()
                {
                    IpAddress = IPAddress.Parse("0.0.0.0"),
                    Port      = 8080
                },
                HttpHost = new Host()
                {
                    IpAddress = IPAddress.Loopback,
                    Port      = 8081
                },
                WebSocketHost = new Host()
                {
                    IpAddress = IPAddress.Loopback,
                    Port      = 8082
                }
            };


            using (var nancyHost = new NancyHost(new Uri("http://localhost:8081")))
                using (var websocketServer = new WebSocketServer("ws://0.0.0.0:8082"))
                    using (var tcpProxy = new TcpProxyServer(configuration))
                    {
                        nancyHost.Start();
                        websocketServer.Start(connection =>
                        {
                            connection.OnOpen    = () => Console.WriteLine("COnnection on open");
                            connection.OnClose   = () => Console.WriteLine("Connection on close");
                            connection.OnMessage = message => Console.WriteLine("Message: " + message);
                        });

                        tcpProxy.Start();

                        Console.WriteLine("Press [Enter] to stop");
                        Console.ReadLine();
                    }
        }
Ejemplo n.º 5
0
        public MiMapWebServer(short publicPort, short privateWebPort, short privateWebSocketPort, MiMapWidgetConfig[] widgets)
        {
            PublicPort           = publicPort;
            PrivateWebPort       = privateWebPort;
            PrivateWebSocketPort = privateWebSocketPort;

            Urls = new[] { $"http://+:{PrivateWebPort}" };

            _proxy = new TcpProxyServer(new TcpProxyConfiguration()
            {
                PublicHost = new Host()
                {
                    IpAddress = IPAddress.IPv6Any,
                    Port      = PublicPort
                },
                HttpHost = new Host()
                {
                    IpAddress = IPAddress.IPv6Loopback,
                    Port      = PrivateWebPort
                },
                WebSocketHost = new Host()
                {
                    IpAddress = IPAddress.Loopback,
                    Port      = PrivateWebSocketPort
                }
            });

            WidgetManager = new WidgetManager(widgets);

            /*
             * _host = new NancyHost(new Uri("http://localhost:8125"), new WebBootstrapper(), new HostConfiguration()
             * {
             *  UrlReservations = new UrlReservations()
             *  {
             *      CreateAutomatically = true
             *  }
             * });*/
        }