fresskoma
fresskoma

Reputation: 25791

Sockets - send and receive

I'm currently writing a chat server in C++. When a user connects to it, I open a socket and I create two threads, one to receive and one to send data.

Now my question:
Do I have to check if the other thread is currently using the socket, or will the send/recv function just wait until the socket is ready?

Upvotes: 3

Views: 1319

Answers (2)

Ry4an Brase
Ry4an Brase

Reputation: 78350

Socket send and receive are independent. You do not need to worry about interleaving them yourself.

Upvotes: 3

EFraim
EFraim

Reputation: 13038

Sending and receiving from TCP socket simultaneously should be entirely fine. (barring any possible OS bugs)

Upvotes: 4

Related Questions