lemni
lemni

Reputation: 13

multi thread receiver in single socket

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.

Upvotes: 1

Views: 206

Answers (1)

makerj
makerj

Reputation: 2259

recv doesn't support content-filtered data receiving.

You should distinguish those kind of messages on your own.

Upvotes: 1

Related Questions