예제 #1
0
        public void Connect(string host, int port)
        {
            var endpoint = IPAddress.Parse(host);

            mSocket = new Socket(endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
            mSocket.Connect(endpoint, port);
            RemoteAddress = (IPEndPoint)mSocket.RemoteEndPoint;
            LocalAddress  = (IPEndPoint)mSocket.LocalEndPoint;
            mKCP          = new KCP((uint)(new Random().Next(1, Int32.MaxValue)), rawSend);
            // normal:  0, 40, 2, 1
            // fast:    0, 30, 2, 1
            // fast2:   1, 20, 2, 1
            // fast3:   1, 10, 2, 1
            mKCP.NoDelay(0, 30, 2, 1);
            mKCP.SetStreamMode(true);
            mRecvBuffer.Clear();
        }
예제 #2
0
        public void Connect(string host, int port)
        {
            IPHostEntry hostEntry = Dns.GetHostEntry(host);

            if (hostEntry.AddressList.Length == 0)
            {
                throw new Exception("Unable to resolve host: " + host);
            }
            var endpoint = hostEntry.AddressList[0];

            mSocket = new Socket(endpoint.AddressFamily, SocketType.Dgram, ProtocolType.Udp);
            mSocket.Connect(endpoint, port);
            RemoteAddress = (IPEndPoint)mSocket.RemoteEndPoint;
            LocalAddress  = (IPEndPoint)mSocket.LocalEndPoint;
            mKCP          = new KCP((uint)(new Random().Next(1, Int32.MaxValue)), rawSend);
            // normal:  0, 40, 2, 1
            // fast:    0, 30, 2, 1
            // fast2:   1, 20, 2, 1
            // fast3:   1, 10, 2, 1
            mKCP.NoDelay(0, 30, 2, 1);
            mKCP.SetStreamMode(true);
            mRecvBuffer.Clear();
        }