Ejemplo n.º 1
0
        void RecAsyncCallback(IAsyncResult result)
        {
            int tsendLen = socket.EndReceive(result);

            if (tsendLen > 0)
            {
                SendData tetstdata = new SendData(11);
                tetstdata.AddInt(3);
                BeginSend(tetstdata.Data, 0, tetstdata.SendLen);

                System.Text.StringBuilder bufferstr = new System.Text.StringBuilder();
                bufferstr.Append("{");
                for (int i = 0; i < tsendLen; i++)
                {
                    if (i != 0)
                    {
                        bufferstr.Append(",");
                    }
                    bufferstr.Append(recBuffer[i]);
                }
                bufferstr.Append("}");
                IPEndPoint endPoint = socket.LocalEndPoint as IPEndPoint;
                var        localIP  = endPoint.Address.ToString();
                string     tmsg     = string.Format("{0}{1}", localIP, bufferstr);
                Debug.Log(tmsg);
            }

            BeginReceive();
        }
Ejemplo n.º 2
0
    void Start()
    {
        // string hostName = Dns.GetHostName();
        // IPHostEntry iPHostEntry = Dns.GetHostEntry(hostName);
        // Debug.Log(iPHostEntry.AddressList[0].ToString());
        IPAddress tip = IPAddress.Parse("127.0.0.1");

        //var mTargetPoint = new IPEndPoint(tip, 200236);
        testServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

        mRecPoint = new IPEndPoint(IPAddress.Any, mLocalPort);
        IPEndPoint tMypoint = new IPEndPoint(IPAddress.Any, mLocalPort);

        testServer.Bind(tMypoint);

        taskStart = true;
        recTask   = Task.Run(RecThread);

        Application.runInBackground = true;

        tetstdata.AddInt(3);
        Debug.Log("测试UDP服务器启动");
    }
Ejemplo n.º 3
0
        void Start()
        {
            kcpObject = new KCP(1, HandleKcpSend);
            kcpObject.NoDelay(1, 10, 2, 1);
            kcpObject.WndSize(128, 128);

            IPAddress tip = IPAddress.Parse("127.0.0.1");

            //var mTargetPoint = new IPEndPoint(tip, 200236);
            testServer = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);

            mRecPoint = new IPEndPoint(IPAddress.Any, mLocalPort);
            IPEndPoint tMypoint = new IPEndPoint(IPAddress.Any, mLocalPort);

            testServer.Bind(tMypoint);

            taskStart = true;
            recTask   = Task.Run(RecThread);

            Application.runInBackground = true;

            tetstdata.AddInt(3);
            Debug.Log("测试KCP服务器启动");
        }