I have a design problem:
I have two threads, a heartbeat/control thread and a messagehandler thread.
Both are sharing the same socket, however the messageHan
Unfortunately,The socket shared by multi-thread is not thread safe.Think about buffer two threads operate on with no lock.
The normal way to implement is with two socket,just like what ftp does.cmd socket and msg socket.
If you wanna implement this by one socket,you can put different type msgs into different queues,and with a third thread consumes the queue and send them through the only socket.
In this way,you can control heartbeat msg priory to data msg.