internal void SetListener(IHyperSocketServer listener)
 {
     this.listener = listener;
 }
Esempio n. 2
0
        /// <summary>
        /// 创建一个服务器超级套接字
        /// </summary>
        /// <param name="ip">监听地址</param>
        /// <param name="tcpPort">tcp端口</param>
        /// <param name="udpPort">udp端口</param>
        /// <param name="connectMaxNum">允许最大连接数</param>
        /// <param name="listener">监听器</param>
        /// <param name="config">配置</param>
        /// <returns></returns>
        public static HyperSocket CreateServer(string ip, uint tcpPort, uint udpPort, uint connectMaxNum, IHyperSocketServer listener, HyperSocketConfig config = null)
        {
            if (config == null)
            {
                config = new HyperSocketConfig();
            }
            if (connectMaxNum > ushort.MaxValue - 1)
            {
                connectMaxNum = ushort.MaxValue - 1;
            }

            var hyperSocket = new HyperSocket(true, ip, tcpPort, udpPort, connectMaxNum, config);

            hyperSocket.tcpServer = new HyperSocketServerModule(ip, (int)tcpPort, (int)connectMaxNum, (int)config.TcpReceiveSize, hyperSocket);
            hyperSocket.udpServer = new HyperSocketServerModule(ip, (int)udpPort, (int)connectMaxNum, (int)config.UdpReceiveSize, hyperSocket);

            hyperSocket.svrListener = listener;

            hyperSocket.tcpServer.SetListener(listener);
            hyperSocket.udpServer.SetListener(listener);

            var r1 = hyperSocket.tcpServer.Init(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp, 0, hyperSocket.tcpServer);
            var r2 = hyperSocket.udpServer.Init(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp, 0, hyperSocket.udpServer);

            if (r1 && r2)
            {
                hyperSocket.IsAlive = true;
                hyperSocket.timeFlow.StartTimeFlowES();
                return(hyperSocket);
            }
            else
            {
                return(null);
            }
        }
 internal void CloseSocket()
 {
     CloseServer();
     hyperSocket = null;
     listener    = null;
 }
Esempio n. 4
0
 /// <summary>
 /// 创建一个服务器超级套接字
 /// </summary>
 /// <param name="ip">监听地址</param>
 /// <param name="port">监听端口 TCP/UDP共用相同端口</param>
 /// <param name="connectMaxNum">允许最大连接数 最大为65534个连接数</param>
 /// <param name="listener">监听器</param>
 /// <param name="config">配置</param>
 /// <returns></returns>
 public static HyperSocket CreateServer(string ip, uint port, uint connectMaxNum, IHyperSocketServer listener, HyperSocketConfig config = null)
 {
     return(CreateServer(ip, port, port, connectMaxNum, listener, config));
 }