Exemplo n.º 1
0
        private void button2_Click(object sender, EventArgs e)
        {
            //删除
            if (listView1.SelectedItems == null || listView1.SelectedItems.Count < 1)
            {
                return;
            }

            if (Config.Listeners == null)
            {
                return;
            }
            ListenerConfig lc = listView1.SelectedItems[0].Tag as ListenerConfig;

            if (lc == null)
            {
                return;
            }

            ListenerConfig[] lcs = new ListenerConfig[Config.Listeners.Length - 1];
            for (int i = 0, j = 0; i < Config.Listeners.Length; i++)
            {
                if (Config.Listeners[i] != lc)
                {
                    lcs[j++] = Config.Listeners[i];
                }
            }
            Config.Listeners = lcs;

            LoadConfig();
            button2.Enabled = false;
        }
Exemplo n.º 2
0
        private void button1_Click(object sender, EventArgs e)
        {
            //新增
            if (Config == null)
            {
                ProxyConfig.Instance = new ProxyConfig();
            }
            ListenerConfig[] lcs = null;
            if (Config.Listeners == null)
            {
                lcs = new ListenerConfig[1];
            }
            else
            {
                lcs = new ListenerConfig[Config.Listeners.Length + 1];
                Config.Listeners.CopyTo(lcs, 0);
            }
            ListenerConfig lc = new ListenerConfig();

            lcs[lcs.Length - 1] = lc;
            lc.Name             = "未命名" + lcs.Length.ToString();
            Config.Listeners    = lcs;

            LoadConfig();

            propertyGrid1.SelectedObject = lc;
        }
Exemplo n.º 3
0
 public void Configure(object config, IApplicationServer server,
                       Type listenerTransport, object listenerTransportConfig,
                       Type appHostTransport, object appHostTransportConfig
                       )
 {
     this.server = server;
     this.config = config as ListenerConfig;
 }
Exemplo n.º 4
0
        // public static TServer CreateSocketServer<TServer, TSession>(ListenerConfig config, StringServerBehavior srvBhvr = null, StringSessionBehavior ssnBhvr = null)
        //     where TServer : SocketServer<TServer, TSession, string>, new()
        //     where TSession : SocketSession<TSession, string>
        // {
        //     return new TServer()
        //             .AddListener(config)
        //             .SetLoggerFactory(new ConsoleLoggerFactory())
        //             .SetMsgFilterFactory(new DefaultMsgFilterFactory<StringMsgFilter, string>())
        //             .SetServerBehavior(srvBhvr ?? new StringServerBehavior())
        //             .SetSessionConfigrator((ssn) =>
        //             {
        //                 if (ssnBhvr != null)
        //                 {
        //                     ssn.SetSessionBehavior(ssnBhvr);
        //                 }
        //             });
        // }

        public static TcpSocketServer CreateStringTcpServer(ListenerConfig listenerConfig, EventSessionBehaviour sessionBehavior = null)
        {
            return(new TcpSocketServer()
                   .AddListener(listenerConfig)
                   .SetLoggerFactory(new ConsoleLoggerFactory())
                   .SetMsgFilterFactory(new DefaultMsgFilterFactory <StringMsgFilter>())
                   .SetSessionConfigrator((ssn) =>
            {
                ssn.SetSessionBehavior(sessionBehavior ?? new EventSessionBehaviour());
            }));
        }
        public void Configure(object conf, IApplicationServer server,
                              Type listenerTransport, object listenerTransportConfig,
                              Type appHostTransport, object appHostTransportConfig)
        {
            this.server = server;
            this.config = conf as ListenerConfig;

            transport = (IListenerTransport)Activator.CreateInstance(listenerTransport);
            transport.Configure(this, listenerTransportConfig);

            appHostTransportType = appHostTransport;
        }
Exemplo n.º 6
0
        private IServerConfig ResolveServerConfig(IServerConfig serverConfig)
        {
            var config = new ServerConfig();

            serverConfig.CopyPropertiesTo(config);

            if (serverConfig.Port > 0)
            {
                var endPointKey      = serverConfig.Name + "_" + serverConfig.Port;
                var instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endPointKey];
                if (instanceEndpoint == null)
                {
                    Trace.WriteLine(string.Format("Failed to find Input Endpoint configuration {0}!", endPointKey), "Error");
                    return(serverConfig);
                }

                var ipEndpoint = instanceEndpoint.IPEndpoint;
                config.Ip   = ipEndpoint.Address.ToString();
                config.Port = ipEndpoint.Port;
            }

            if (config.Listeners != null && config.Listeners.Any())
            {
                var listeners = config.Listeners.ToArray();

                var newListeners = new List <ListenerConfig>(listeners.Length);

                for (var i = 0; i < listeners.Length; i++)
                {
                    var listener = listeners[i];

                    var endPointKey      = serverConfig.Name + "_" + listener.Port;
                    var instanceEndpoint = RoleEnvironment.CurrentRoleInstance.InstanceEndpoints[endPointKey];
                    if (instanceEndpoint == null)
                    {
                        Trace.WriteLine(string.Format("Failed to find Input Endpoint configuration {0}!", endPointKey), "Error");
                        return(serverConfig);
                    }

                    var newListener = new ListenerConfig();
                    newListener.Ip      = instanceEndpoint.IPEndpoint.Address.ToString();
                    newListener.Port    = instanceEndpoint.IPEndpoint.Port;
                    newListener.Backlog = listener.Backlog;

                    newListeners.Add(newListener);
                }

                config.Listeners = newListeners;
            }

            return(config);
        }
Exemplo n.º 7
0
        public void OnAttach(int seq, AttacherConfig toConfig, ListenerConfig fromConfig)
        {
            if (null == toConfig || null == fromConfig)
            {
                Logger.Error("OnAttach: config == null");
                return;
            }

            m_nSequence  = seq;
            m_toConfig   = toConfig;
            m_fromConfig = fromConfig;
            Connect(m_toConfig.m_strIP, m_toConfig.m_nPort);
            m_eToServerType = eServerType.Center;
        }
Exemplo n.º 8
0
        public static IHostBuilder CreateHostBuilder(string[] args, ListenerConfig config)
        {
            Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

            return(Host.CreateDefaultBuilder(args)
                   .UseWindowsService()
                   .ConfigureServices((hostContext, services) =>
            {
                hostContext.HostingEnvironment.ContentRootPath = ProgramUtils.GetBaseDir();
                services.AddTransient <ListenerConfig>((s) => config);
                services.AddHostedService <UdpListenerService>();
                RegisterCmdHandlers(services);
            }).ConfigureLogging((logging) =>
            {
                logging.ClearProviders();
                logging.AddNLog();
            }));
        }
        protected virtual IHazelcastInstance CreateClient()
        {
            var clientFactory = new HazelcastClientFactory();
            var resetEvent    = new ManualResetEventSlim();
            var listener      = new ListenerConfig(new LifecycleListener(l =>
            {
                if (l.GetState() == LifecycleEvent.LifecycleState.ClientConnected)
                {
                    resetEvent.Set();
                }
            }));
            var client = clientFactory.CreateClient(c =>
            {
                ConfigureClient(c);
                c.AddListenerConfig(listener);
            });

            Assert.IsTrue(resetEvent.Wait(30 * 1000), "Client did not start after 30 seconds");
            return(client);
        }
Exemplo n.º 10
0
        public Listener(ListenerConfig config)
        {
            var ipAddress = IPAddress.None;

            switch (config.Ip.ToLower())
            {
            case ("any"):
                ipAddress = IPAddress.Any;
                break;

            case ("ipv6any"):
                ipAddress = IPAddress.IPv6Any;
                break;

            default:
                ipAddress = IPAddress.Parse(config.Ip);
                break;
            }

            EndPoint = new IPEndPoint(ipAddress, config.Port);
        }
Exemplo n.º 11
0
 /// <summary>
 /// 初始化监听器类的新实例
 /// </summary>
 /// <param name="config"></param>
 public Listener(ListenerConfig config)
 {
     Config = config;
 }
Exemplo n.º 12
0
 public UdpListenerService(ILogger <UdpListenerService> logger, CommandExecutorService commandExecutorService, ListenerConfig listenerConfig)
 {
     _logger = logger;
     _commandExecutorService = commandExecutorService;
     _listenerConfig         = listenerConfig;
 }
Exemplo n.º 13
0
 public TServer AddListener(ListenerConfig lstnrCnfg)
 {
     _listenerConfigs.Add(lstnrCnfg);
     return(this as TServer);
 }
Exemplo n.º 14
0
 /// <summary>
 /// 初始化监听器类的新实例
 /// </summary>
 /// <param name="config"></param>
 public Listener(ListenerConfig config) => Config = config;
Exemplo n.º 15
0
        static void Main(string[] args)
        {
            var server = new MyWebSocketServer();

            server.NewSessionConnected += ServerNewSessionConnected;
            //server.NewSessionConnected += new SessionHandler<MyWebSocketSession>(ServerNewSessionConnected);
            server.NewMessageReceived += ServerNewMessageRecevied;
            server.SessionClosed      += ServerSessionClosed;

            server.NewDataReceived += (session, bytes) =>
            {
                //接收到新的二进制消息
            };

            Timer timer = new Timer((data) =>
            {
                //对当前已连接的符合条件的会话进行广播
                var sessions = server.GetSessions(c => c.MyCustomerId == "1");
                if (sessions != null)
                {
                    foreach (var session in sessions)
                    {
                        session.Send(DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
                    }
                }
            }, null, 10000, 10000);

            try
            {
                var listenerConfig1 = new ListenerConfig()
                {
                    Ip   = "127.0.0.1",
                    Port = 2012
                };

                var listenerConfig2 = new ListenerConfig()
                {
                    Ip   = "127.0.0.1",
                    Port = 4142
                };

                var list = new List <ListenerConfig>
                {
                    listenerConfig1,
                    listenerConfig2
                };

                var serverConfig = new ServerConfig
                {
                    Ip   = "192.168.1.73",
                    Port = 2012,
                    Name = "DyWebSocketServer8",
                    //Listeners = list,
                    MaxConnectionNumber = 311 //最大连接数,默认100
                };


                var filter = new AuthorizeFilter();
                filter.Initialize("DyWebSocketServer8", server);
                //filter.AllowConnect()

                var filters = new List <AuthorizeFilter>()
                {
                    filter
                };

                bool s1 = server.Setup(serverConfig, connectionFilters: filters);
                bool s2 = server.Start(); //启动侦听
                //bool s1 = server.Setup("127.0.0.1", 4141); //对要侦听的IP及端口进行设置
            }
            catch (Exception ex)
            {
                Console.WriteLine("异常:" + ex.Message);
            }
            Console.ReadKey();

            server.Stop();
        }
Exemplo n.º 16
0
 public ISocketServer AddListener(ListenerConfig lstnrCnfg)
 {
     _listenerConfigs.Add(lstnrCnfg);
     return(this);
 }