2
votes

I'm using a C socket library I found online to implement a tcp socket data transfer program.

Is it possible to make 2 threads share the same socket connection (1 read and 1 write), and have the read thread perform a blocking read and recv data while the write thread constantly writes data?

All of the example socket programs I've seen only do 1 way communication, or send data only after it receives.

Thank you.

1

1 Answers

2
votes

I don't know of any technical reason why you can't do that. Whether it's advisable or not for your situation is another question. :)

The main situation in which you'd want to avoid this multi-threaded type of approach is if reads and writes are dependent on each other at the application level. I don't really know what you're doing with respect to handling the data, but the reader/writer approach can be difficult to unwind.