NetMQ.ReceivingSocketExtensions.TryReceiveMultipartMessage C# (CSharp) Method

TryReceiveMultipartMessage() public static method

Attempt to receive all frames of the next message from socket. If no message is available within timeout, return false.
public static TryReceiveMultipartMessage ( [ socket, System.TimeSpan timeout, [ message, int expectedFrameCount = 4 ) : bool
socket [ The socket to receive from.
timeout System.TimeSpan The maximum period of time to wait for a message to become available.
message [ The received message. Untouched if no message was available.
expectedFrameCount int Specifies the initial capacity of the used /// to buffer results. If the number of frames is known, set it here. If more frames arrive than expected, /// an extra allocation will occur, but the result will still be correct.
return bool
        public static bool TryReceiveMultipartMessage([NotNull] this IReceivingSocket socket, TimeSpan timeout, [CanBeNull] ref NetMQMessage message, int expectedFrameCount = 4)
        {
            var msg = new Msg();
            msg.InitEmpty();

            // Try to read the first frame
            if (!socket.TryReceive(ref msg, timeout))
            {
                msg.Close();
                return false;
            }

            // We have one, so prepare the container
            if (message == null)
                message = new NetMQMessage(expectedFrameCount);
            else
                message.Clear();

            // Add the frame
            message.Append(new NetMQFrame(msg.CloneData()));

            // Rinse and repeat...
            while (msg.HasMore)
            {
                socket.Receive(ref msg);
                message.Append(new NetMQFrame(msg.CloneData()));
            }

            msg.Close();
            return true;
        }

Same methods

ReceivingSocketExtensions::TryReceiveMultipartMessage ( [ socket, [ message, int expectedFrameCount = 4 ) : bool