Reputation: 25791
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
Reputation: 78350
Socket send and receive are independent. You do not need to worry about interleaving them yourself.
Upvotes: 3
Reputation: 13038
Sending and receiving from TCP socket simultaneously should be entirely fine. (barring any possible OS bugs)
Upvotes: 4