0

Here is my scenario:

  • Multiple sockets on one application
  • I want to receive and send on any number of these sockets

The only solution I have found so far to get around threading issues and bizzare exceptions is:

  • Each socket has it's own thread
  • Each socket has it's own concurrent queue which it constantly checks to see if it has a message to send
  • To send from a specific socket, regardless of thread, then you just add the message to the correct socket concurrent queue

However, this get's pretty costly. I am not a big fan of threading in general, and I have a niggly feeling there's a much better way. I am thinking about the poller - it allows you to receive from multiple sockets without needing to create a new thread per socket (as far as I'm aware). If this is right, is there no way to get it to send pending messages?

Otherwise, is multiple threads my only option? Thanks

Fred Johnson
  • 2,539
  • 3
  • 26
  • 52
  • I don't understand, from your description, why you feel you need multiple threads in the first place. What problems were you running into that threading seemed to solve? – Jason Dec 21 '15 at 21:18
  • I kept getting several messaging errors. I found this which led me to trying multiple threads, but if they can be avoided it would be better: https://sachabarbs.wordpress.com/2014/08/30/zeromq-sending-from-multiple-sockets/ – Fred Johnson Dec 22 '15 at 11:06
  • What confuses me is which thread the socket is actually on when you use a poller -> it's own? In which case to avoid multiple threads for receive and sending messages on a socket. – Fred Johnson Dec 22 '15 at 11:08
  • Perhaps you should post some of your code. Pollers work within a single thread. If you have a version of your code from before you split it into multiple threads, maybe we can try to deal with those errors you were seeing directly rather than going the threaded route at all. – Jason Dec 22 '15 at 11:59

0 Answers0