开发者

read and write thread using a single tcp socket

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 开发者_Python百科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.


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜