Now my question is, can we set up a socket(TCP/IP) in such a way that it only writes or reads.
When you do shutdown of an end, you can do only the other operation. Hope this helped.
As per your explanation, if B is not intended for reading, then do the shutdown of read end at B, and write end of A..
| [reply] |
One of the wisdom I got from your post is that one can read and write between the process with a single TCP connection. Also I cross verified from the below link
Note: Actual point discussed over the link specified is not related to this !! But it has underlying concepts related to the TCP !!
So there is nothing wrong in performing both read and write in a single socket. Define in your coding as per your requirement/need in both end of the connection ( i.e in two related process ) !! | [reply] |
You can use the select on socket handler, which will let you know whether the socket is ready for read or write. Based on the select output you can perform read or write operation.
| [reply] |
This question is ignoring reads, to avoid blocking.
| [reply] |
spmlingam's answer does address your problem. When B is about to write, use select to check if there's anything to read. If there's is, read until there isn't. Then proceed to write.
sathiya.sw's shutdown solution sounds more promising, though.
| [reply] [d/l] [select] |