public void Listen(string host, int port, int backlog, MDSocketOption socketOption)
        {
            MDListener client_listener = new MDListener();

            client_listener.OnNewClientCallback += OnNewClient;
            client_listener.Start(host, port, backlog, socketOption);

            byte check_interval = 10;

            UserManager.StartHeartbeatChecking(check_interval, check_interval);
        }
        //리스너는 여러개가 될수 있다.
        public void Start(string host, int port, int backlog, MDSocketOption socketOption)
        {
            //최대 커넥션수, 버퍼크기
            RemoteSocketOpt = socketOption;

            //TCP소켓 생성
            ListenSocket = new Socket(AddressFamily.InterNetwork,
                                      SocketType.Stream, ProtocolType.Tcp);


            IPAddress address;

            if (host == "0.0.0.0" || host == "localhist")
            {
                address = IPAddress.Any;
            }
            else
            {
                address = IPAddress.Parse(host);
            }

            //클라이언트가 도착하는 인터넷 프로토콜의 끝점
            var endpoint = new IPEndPoint(address, port);


            try
            {
                //주소정보 바인딩 리슨 시작
                ListenSocket.Bind(endpoint);
                ListenSocket.Listen(backlog);

                //비동기 호출시 필요한 객체 와 그것과 연결된 함수.
                Accept_Args            = new SocketAsyncEventArgs();
                Accept_Args.Completed += new EventHandler <SocketAsyncEventArgs>(OnAcceptCompleted);

                //리슨을 수행할 스레드
                var listen_thread = new Thread(DoListen);
                listen_thread.Start();
            }
            catch (Exception e)
            {
                Console.WriteLine(e.Message);
            }
        }
Beispiel #3
0
        public void Connect(IPEndPoint remoteEndpoint, MDSocketOption socketOption)
        {
            ClientSocket = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);

            ClientSocket.NoDelay = socketOption.NoDelay;

            SocketAsyncEventArgs event_arg = new SocketAsyncEventArgs();

            event_arg.Completed     += OnConnectCompleted;
            event_arg.RemoteEndPoint = remoteEndpoint;


            bool pending = ClientSocket.ConnectAsync(event_arg);

            if (pending == false)
            {
                OnConnectCompleted(null, event_arg);
            }
        }