Ejemplo n.º 1
0
 public ListenParas(Socket _socket, ISessionfactory _factory, string _host, UInt32 _port)
 {
     ServerSocket = _socket;
     Factory      = _factory;
     Host         = _host;
     Port         = _port;
 }
Ejemplo n.º 2
0
        private void process_accept(Socket client_socket, ISessionfactory factory)
        {
            if (client_socket == null || factory == null)
            {
                return;
            }

            ISession session = factory.CreateSession();

            if (session == null)
            {
                return;
            }

            IConnection conn = conn_mgr.Create(this, client_socket, session);

            if (conn == null)
            {
                return;
            }
            conn.DoAsyncReceive();
        }
Ejemplo n.º 3
0
        public bool Listen(string host, UInt32 port, ISessionfactory factory, int listen_max_count)
        {
            if (factory == null)
            {
                return(false);
            }

            if (listen_max_count == 0)
            {
                listen_max_count = NetDef.LISTEN_MAX_COUNT;
            }

            Socket socket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            if (socket == null)
            {
                Log.ErrorAf("[Net] Host={0} Port={1} Listen Socket Error", host, port);
                return(false);
            }

            IPEndPoint listen_endpoint = new IPEndPoint(IPAddress.Parse(host), (int)port);

            try
            {
                socket.Bind(listen_endpoint);
                socket.Listen(listen_max_count);
                ListenParas paras = new ListenParas(socket, factory, host, port);
                socket.BeginAccept(on_accept, paras);
            }
            catch (System.Exception ex)
            {
                Log.ErrorAf("[Net] Host={0} Port={1} BeginAccept Error={0}", ex.ToString());
                return(false);
            }

            return(true);
        }
Ejemplo n.º 4
0
 public void SetSessionFactory(ISessionfactory factory)
 {
     session_factory = factory;
 }