Ejemplo n.º 1
0
 public void Update()
 {
     if (m_tcpClient != null && m_tcpClient.ClientConnected())
     {
         m_tcpClient?.ClientReceive();
     }
 }
Ejemplo n.º 2
0
    public void ClientEnReceive(IAsyncResult ar)
    {
        //数据处理
        int receiveLength = m_Socket.EndReceive(ar);
        //吧结束完毕的字节数组转化为string类型
        string dataStr = System.Text.Encoding.UTF8.GetString(data, 0, receiveLength);

        m_receiveCallBack?.Invoke(dataStr);
        if (m_IsServer)
        {
            for (int i = 0; i < ServerLoop.Instance.List_clients.Count; i++)
            {
                TcpSocket tmpsocket = ServerLoop.Instance.List_clients[i];
                if (tmpsocket.ClientConnected())
                {
                    GameMain.Instance.Log("  dataStr " + dataStr);
                    tmpsocket.ClientSeed(System.Text.Encoding.UTF8.GetBytes("服务器回复:我收到了" + dataStr));
                }
            }
        }
    }