tags:

views:

314

answers:

2

Hey,

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?

Regards,
x3ro

+2  A: 

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

EFraim
+1  A: 

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

Ry4an
They are independant on conceptual level, but there is common state on transport layer.
EFraim
Surely, but that's abstracted away entirely by the Sockets API. Heck, given the ACKs ever send or receive is both a send and receive.
Ry4an