Esempio n. 1
0
        /// <summary>
        /// Receive a string message from a remote socket in non-blocking mode with a specified timeout.
        /// </summary>
        /// <param name="socket">A <see cref="ZmqSocket"/> object.</param>
        /// <param name="encoding">The <see cref="Encoding"/> to use when converting the received buffer to a string.</param>
        /// <param name="timeout">A <see cref="TimeSpan"/> specifying the receive timeout.</param>
        /// <returns>A <see cref="string"/> containing the message received from the remote endpoint.</returns>
        /// <exception cref="ArgumentNullException"><paramref name="encoding"/> is null.</exception>
        /// <exception cref="ZmqSocketException">An error occurred receiving data from a remote endpoint.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ZmqSocket"/> has been closed.</exception>
        /// <exception cref="NotSupportedException">The current socket type does not support Receive operations.</exception>
        public static string Receive(this ZmqSocket socket, Encoding encoding, TimeSpan timeout)
        {
            VerifySocket(socket);
            VerifyEncoding(encoding);

            int messageSize;

            byte[] buffer = socket.Receive(null, timeout, out messageSize);

            return(encoding.GetString(buffer, 0, messageSize));
        }
Esempio n. 2
0
        /// <summary>
        /// Receive a single frame from a remote socket in non-blocking mode with a specified timeout.
        /// </summary>
        /// <remarks>
        /// This overload will receive all available data in the message-part. If the buffer size of <paramref name="frame"/>
        /// is insufficient, a new buffer will be allocated.
        /// </remarks>
        /// <param name="socket">A <see cref="ZmqSocket"/> object.</param>
        /// <param name="frame">A <see cref="Frame"/> that will store the received data.</param>
        /// <param name="timeout">A <see cref="TimeSpan"/> specifying the receive timeout.</param>
        /// <returns>A <see cref="Frame"/> containing the data received from the remote endpoint.</returns>
        /// <exception cref="ZmqSocketException">An error occurred receiving data from a remote endpoint.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ZmqSocket"/> has been closed.</exception>
        /// <exception cref="NotSupportedException">The current socket type does not support Receive operations.</exception>
        public static Frame ReceiveFrame(this ZmqSocket socket, Frame frame, TimeSpan timeout)
        {
            VerifySocket(socket);

            if (frame == null)
            {
                frame = Frame.Empty;
            }

            int size;

            frame.Buffer = socket.Receive(frame.Buffer, timeout, out size);
            SetFrameProperties(frame, socket, size);

            return(frame);
        }
Esempio n. 3
0
        /// <summary>
        /// Receive a single frame from a remote socket in blocking mode.
        /// </summary>
        /// <remarks>
        /// This overload will receive all available data in the message-part. If the buffer size of <paramref name="frame"/>
        /// is insufficient, a new buffer will be allocated.
        /// </remarks>
        /// <param name="socket">A <see cref="ZmqSocket"/> object.</param>
        /// <param name="frame">A <see cref="Frame"/> that will store the received data.</param>
        /// <returns>A <see cref="Frame"/> containing the data received from the remote endpoint.</returns>
        /// <exception cref="ZmqSocketException">An error occurred receiving data from a remote endpoint.</exception>
        /// <exception cref="ObjectDisposedException">The <see cref="ZmqSocket"/> has been closed.</exception>
        /// <exception cref="NotSupportedException">The current socket type does not support Receive operations.</exception>
        public static Frame ReceiveFrame(this ZmqSocket socket, Frame frame)
        {
            VerifySocket(socket);

            if (frame == null)
            {
                frame = new Frame(0);
            }

            int size;

            frame.Buffer = socket.Receive(frame.Buffer, out size);
            SetFrameProperties(frame, socket, size);

            return(frame);
        }