Is socket.shutdown(1) useless

pyguy2 at gmail.com pyguy2 at gmail.com
Wed Apr 13 09:00:24 EDT 2005


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




More information about the Python-list mailing list