targetsmart has asked for the wisdom of the Perl Monks concerning the following question:
Dear monks,
I faced one problem with sockets and found a solution I just wanted to know I am correct.
I had two socket programs, A and B, A will be receiving data from B, A's socket only reads and B's socket only writes.
Now when the A's socket apart from reading also tends to write some data into the B's socket, but B is not reading, this makes both the program A and B to hang after some time.
I predicted that the read side of the socket is full in B side, so I started to read the data from B's side also apart from writing, the problem got solved.
Now my question is, can we set up a socket(TCP/IP) in such a way that it only writes or reads.(because B is only a simulation program). or just ignore read side at the socket level.
Re: socket read buffer full
by sathiya.sw (Monk) on Jan 06, 2009 at 15:24 UTC
|
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] |
Re: socket read buffer full
by Dhanasekar (Acolyte) on Jan 06, 2009 at 12:24 UTC
|
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] |
Re: socket read buffer full
by spmlingam (Scribe) on Jan 07, 2009 at 07:29 UTC
|
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] |
|
|
|
|