By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
439,993 Members | 1,883 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 439,993 IT Pros & Developers. It's quick & easy.

Is socket.shutdown(1) useless

P: n/a
Issues of socket programming can be wierd, so I'm looking for some
comments.

In my python books I find exclusive use of socket.close(). From my
other readings, I know about a "partial close operation". So, I figured
it would be useful to post some code about how socket.close() has an
implicit send in it and you can actually gain some clarity by being
more explicit with the partial close which means splitting
socket.close() up into socket.shutdown(1) and socket.close().

And got a response in essence saying, why bother, socket.shutdown,
isn't useful.

Here is my thinking:

With a standard socket.close(), the client closes the socket
immediately after the implicit send. This means the client assumes it
was ok to actually close the socket, independant of how the server
reacts to that last bit of data. To me that is an assumption you may
not always want to make.

If, instead, the client does a socket.shutdown(1) to say it is done
sending, it can still recv and wait for the server to respond with
either:
1)yep, I agree you finished sending
or
2)I know you are done,and I got your data, but I do not think you are
done

To me these seem like a very useful distinction, since now if the
client cares, it can find out if it's final communication did matter.
It helps avoid what I call the princess bride phenomenon of #2:

"You keep using that word. I do not think it means what you think it
means."

So, is this whole business with socket.shutdown mostly useless? So
useless that I cannot find any mention of it in 2nd edition,
Programming Python.

john

Jul 18 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
py****@gmail.com wrote:
In my python books I find exclusive use of socket.close(). From my
other readings, I know about a "partial close operation". So, I figured
it would be useful to post some code about how socket.close() has an
implicit send in it and you can actually gain some clarity by being
more explicit with the partial close which means splitting
socket.close() up into socket.shutdown(1) and socket.close().

And got a response in essence saying, why bother, socket.shutdown,
isn't useful.


I had to use socket.shutdown once because the socket architecture we had
relied on sending a piece of data, waiting for it to be processed, and
then receiving a result back. The server on the other end of the socket
wouldn't process anything until it was sure that all data had been sent.
So our code basically looked like:

s = socket.socket(...)
s.connect(...)
s.send(...)
s.shutdown(1)
data = s.makefile().read()
s.close()

STeVe
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.