在HandleProtocolData函数(或Received事件)中,已经包含了协议参数,所以直接自行筛选即可。

    1. service.Received += (client, protocol, byteBlock) =>
    2. {
    3. //从客户端收到信息
    4. //Protocol系的数据,前两个字节为协议,所以真实数据应该偏移2个单位。
    5. if (protocol == 10)
    6. {
    7. string mes = Encoding.UTF8.GetString(byteBlock.Buffer, 2, byteBlock.Len - 2);
    8. Console.WriteLine($"已从{client.Name}接收信息:{mes}");
    9. }
    10. };