
Also I tried to run it on different Windows-machines and it only worked in about 25% of the cases. I know that there is a ZeroMQ-Plugin, but it has some Unresolved Issues in terms of operability on different platforms. I do not want to burden myself with an intense amount of platform-specific code, neither do I want to be dependent on plugins that might break under certain conditions on each platform. So I'm really careful with the plugin-choice. It must be running on Android/iOS/Windows/MacOS/Linux/Web. I want to use/ subscribe a to a pub-socket on a server that implements ZeroMQ ( ) There is no operating system/kernel level indication that will give you any kind of a guarantee as to the amount of a send() or write() call on a socket will accept.

You will need to figure out which logic/algorithm based solution will work best for your specific program. The number of possible, alternative solutions has no limit. This would avoid having all execution thread wedged by a hung socket, at expense of grown memory, that's holding all unsent data.īut that's just one possible approach. Just one possibility would be a dedicated execution thread that handles all socket input/output, and all your other execution threads sending their messages to the socket thread, instead of writing to the socket directly. Each eventual solution needs to be tailored based on each program's unique requirements and purpose. There is no single, cookie-cutter, paint-by-numbers, solution to this that works in every situation, in every program, that needs to do something like this. It goes without sending that this leaves open a possibility that a blocked/hung socket will result in a single thread locking this mutex for an excessive amount of time, until the socket times out and your execution thread ends up dealing with a failed send() or write(), in whatever fashion it is already doing now (you are, of course, checking the return value from send/write, and handling the exception conditions appropriately). It will be necessary to handle the synchronization at this level, by employing a mutex that each thread locks before sending its message and unlocking it only after the entire message is sent. Sent to the same socket by different threads Not only there's a chance of that, it is pretty much going to be a certainty, at one point or another. But, my worry is that beacuse Tcp is a stream the client will receive fragments of each message and I was thinking that adding framing to each message I could rebuild the message on the client side, if I knew how many bytes are sent at a time.Īlthough the call to ::send() is done sequentially, is the any chance that the byte stream is still mixed? The loop is mutexed so can be seen as thread safe, so each thread has to perform the sending after the other. Thus, go with the loop solution until all the bytes are sent.

In some cases where messages are large multiple calls to ::send() are required as not all the bytes are sent at the initial call.

Is there any way to know exactly how many bytes can be sent before sending? If the socket will allow for the entire message, or that the message will be fragmented and by how much?Ģ messages are sent to the same socket by different threads at the same time on the same tcp client via ::send().

) where sent_bytes is only 256 bytes so this needs to be called again. I'm aware that the ::send within a Linux TCP server can limit the sending of the payload such that ::send needs to be called multiple times until the entire payload is sent.
