Ad

Multi Thread Receiver In Single Socket

- 1 answer

With TCP, I'm designing some programs like next.

clients' recv in many threads are waiting for one server's send message. However, there is a condition. recv is waiting for a specific send message.

For example

client

thread 1: recv (key = 4)
thread 2: recv (key = 6)
thread 3: recv (key = 9)

server

send(value = A) for key 4 - send(value = B) for key 9 - send(value = C) for key 6

then, thread 1 should get value A, thread 3 should get value B, thread 2 should get value C

how can recv function distinguish server send messages? Is there any good idea or solution? Thanks.

Ad

Answer

recv doesn't support content-filtered data receiving.

You should distinguish those kind of messages on your own.

Ad
source: stackoverflow.com
Ad