Multicast(IList<Player> clients, bool reliable, byte cmd, byte[] buffer, bool kernel, bool serialize
/// <summary>
/// 网络多播, 发送数据到clients集合的客户端 (灵活数据包)
/// </summary>
/// <param name="clients">客户端集合</param>
/// <param name="reliable"></param>
/// <param name="cmd"></param>
/// <param name="buffer">要包装的数据,你自己来定</param>
/// <param name="kernel">内核? 你包装的数据在客户端是否被内核NetConvert序列化?</param>
/// <param name="serialize">序列化? 你包装的数据是否在服务器即将发送时NetConvert序列化?</param>
public virtual void Multicast(IList<Player> clients, bool reliable, byte cmd, byte[] buffer, bool kernel, bool serialize)
{
if (buffer.Length / MTU > ushort.MaxValue)
{
Debug.LogError("数据太大,请分块发送!");
return;
}
for (int i = 0; i < clients.Count; i++)
{
var client = clients[i];
if (client == null)
continue;
if (client.CloseSend)
continue;
if (!reliable)
{
if (client.udpRPCModels.Count >= ushort.MaxValue)
{
Debug.LogError($"[{client.UserID}]数据缓存列表超出限制!");
return;
}
client.udpRPCModels.Enqueue(new RPCModel(cmd, buffer, kernel, serialize) { bigData = buffer.Length > short.MaxValue });
}
else
{
if (client.tcpRPCModels.Count >= ushort.MaxValue)
{
Debug.LogError($"[{client.UserID}]数据缓存列表超出限制!");
return;
}
client.tcpRPCModels.Enqueue(new RPCModel(cmd, buffer, kernel, serialize) { bigData = buffer.Length > short.MaxValue });
}
}
}
上一页Multicast(IList<Player> clients, bool reliable, byte cmd, byte[] buffer)下一页Multicast(IList<Player> clients, bool reliable, RPCModel model)
最后更新于
这有帮助吗?