示例#1
0
    public static SenderPacketCollection Receive(UdpSocket udpSocket, List <RemoteSender> remoteSenders)
    {
        var senderEndPoints        = new List <IPEndPoint>();
        var senderPacketCollection = new SenderPacketCollection();

        foreach (var remoteSender in remoteSenders)
        {
            senderEndPoints.Add(remoteSender.SenderEndPoint);
            senderPacketCollection.SenderPacketSets.Add(remoteSender.SenderSessionId, new SenderPacketSet());
        }

        // During this loop, SocketExceptions will have endpoint information.
        foreach (var senderEndPoint in senderEndPoints)
        {
            while (true)
            {
                var packet = udpSocket.ReceiveFrom(senderEndPoint);
                if (packet == null)
                {
                    break;
                }

                CollectPacket(packet, senderPacketCollection);
            }
        }

        // During this loop, SocketExceptions won't have endpoint information but connection messages will be received.
        while (true)
        {
            var packet = udpSocket.Receive();
            if (packet == null)
            {
                break;
            }

            CollectPacket(packet, senderPacketCollection);
        }

        return(senderPacketCollection);
    }