예제 #1
0
파일: Tcp.cs 프로젝트: soulgundam/dd
        public void Close()
        {
            LinkedListNode<NetHandle> curNode = handleList_.First;
            LinkedListNode<NetHandle> nextNode;
            while (curNode != null)
            {
                nextNode = curNode.Next;
                curNode.Value.Close();
                handleList_.Remove(curNode);
                curNode = nextNode;
            }

            mainHandle_.Close();
            mainHandle_ = null;
        }
예제 #2
0
파일: Tcp.cs 프로젝트: soulgundam/dd
        public bool Connect(string ip, int port)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                sock.Blocking = false;
                sock.Connect(ip, port);
            }
            catch (SocketException e)
            {
                if (e.ErrorCode != 10035)
                {
                    Log.E(e.Message);
                    return false;
                }
            }

            mainHandle_ = new NetHandle(sock);
            onUpdate_ = ConnectorTryConnect;
            return true;
        }
예제 #3
0
파일: Tcp.cs 프로젝트: soulgundam/dd
        public bool Listen(int port)
        {
            Socket sock = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
            try
            {
                IPEndPoint ipe = new IPEndPoint(IPAddress.Any, port);
                sock.Bind(ipe);
                sock.Listen(backLog_);
                sock.Blocking = false;
                mainHandle_ = new NetHandle(sock);
            }
            catch (Exception e)
            {
                Log.E(e.Message);
                return false;
            }

            onUpdate_ = AcceptorUpdate;
            return true;
        }
예제 #4
0
파일: Tcp.cs 프로젝트: soulgundam/dd
        void AcceptedToHandle(int count)
        {
            Socket sock;
            NetHandle handle;
            LinkedListNode<Socket> curNode = acceptedList_.First;
            LinkedListNode<Socket> nextNode;
            while (curNode != null)
            {
                sock = curNode.Value;
                nextNode = curNode.Next;
                acceptedList_.Remove(curNode);
                curNode = nextNode;

                sock.Blocking = false;
                sock.ReceiveBufferSize = 65536;
                handle = new NetHandle(sock);
                handleList_.AddLast(handle);
                onConnect_(handle);

                if (--count <= 0)
                    return;
            }
        }