[zeromq-dev] Using ZMQ_STREAM as tcp client. Why am I receiving extra info?

Juergen Gnoss jgnoss at hotmail.com
Thu Nov 30 02:26:11 CET 2017

you actually receive 2 frames from the zmq stream socket, you have to strip them of one by one.

The first one you have to conserve in case you want to respond to that peer the message comes from.

The second one is your actual data.


From: zeromq-dev <zeromq-dev-bounces at lists.zeromq.org> on behalf of Brian Wagener <Android at forceconstant.com>
Sent: Wednesday, November 29, 2017 3:00 PM
To: zeromq-dev at lists.zeromq.org
Subject: [zeromq-dev] Using ZMQ_STREAM as tcp client. Why am I receiving extra info?

I have an application that uses zeromq for various things and want to also use it as a tcp client for other external connections. Currently if the external tcp server sends data, the client receives 5 byte id, 0 bytes, 5 bytes, and then actual message. How do I get zeromq not to send this stuff.

#include <iostream>

#include <string>

#include <zmq.h>

#include <cstring>

#include <assert.h>

#include <chrono>

#include <thread>

int main()


void *mpSocketContext = zmq_ctx_new();

/* Create ZMQ_STREAM socket */

void *mpSerialSocket = zmq_socket(mpSocketContext, ZMQ_STREAM);

void *mpSocket = mpSerialSocket;

bool aeBlocking = true;

std::string asAddress = "<>";

asAddress = "tcp://" + asAddress;

std::cout << "tcSerialServerPort::tcSerialServerPort: connecting to " << asAddress << std::endl;

int rc = zmq_connect(mpSerialSocket, asAddress.c_str());

if (rc != 0)

std::cout << "ZMQ ERROR: zmq_connect " << zmq_strerror(zmq_errno()) << std::endl;

uint8_t id [256];

size_t id_size = 256;

rc = zmq_getsockopt (mpSerialSocket, ZMQ_IDENTITY, id, &id_size);

assert(rc == 0);



zmq_msg_t msg;


size_t lnBytesReceived = 0;

std::string lsStr;

lnBytesReceived = zmq_recvmsg(mpSocket, &msg, aeBlocking ? 0 : ZMQ_DONTWAIT);

lsStr = std::string(static_cast<const char*>(zmq_msg_data(&msg)),


std::cout << "Received Bytes=" << lsStr.size() << " Data=" << lsStr << std::endl;






return 0;


Brian Wagener

Lockheed Martin Undersea Systems

Software Engineer Stf

West Palm Beach, FL

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.zeromq.org/pipermail/zeromq-dev/attachments/20171130/b267556d/attachment.htm>

More information about the zeromq-dev mailing list