Unity - A计划(永久有效期) 扫二维码继续学习 二维码时效为半小时

(197评价)
价格: 4431.00元

在这里EndReceive前后端都需要做判断,不然前端会报错 

static void ReceiveCallback(IAsyncResult ar)
{

    try
    {

        Socket pocket = (Socket)ar.AsyncState;
        int num = pocket.EndReceive(ar);
        if (num <= 0)
        {
            Console.WriteLine("接收到的数据数量:" + num );
        }
        else {
            string msg = Encoding.UTF8.GetString(msgBuff);
            Console.WriteLine("接收到的数据:" + msg);
            Receive(pocket, ReceiveCallback);
        }
    }
    catch (Exception ex)
    {
        Console.WriteLine("接收数据失败! 异常 :" + ex.ToString());
    }
}

 

[展开全文]
小乐哈 · 06-04 · 0