python socket query

Piet van Oostrum piet at vanoostrum.org
Mon Dec 23 14:23:24 CET 2013


smilesonisamal at gmail.com writes:

> Hi,
>    I am trying to write a TCP socket program in python. I am using python 2.6 in linux. 
>
> I referred following link:
> http://www.ibm.com/developerworks/linux/tutorials/l-pysocks/section4.html
> I am actually writing the client-side stream socket.
> I wrote a small program which creates the socket, bind to the socket, connect to socket and send() close(). I see that there is no reply coming from server and the TCP disconnect happens.
> import socket
>
> def tcp(host, request, port=34567):
>
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
>
> s.connect((host, port))
>
> s.send(request)
>
> reply = s.recv(2**14)
>
> s.close()
>
> return reply
>
> My problem is even if the request is sent the length(reply) is is 0. I tried to put a timeout of 1 sec s.settimeout() call after the send call but it doesnot help.
>
> I tried by commenting s.close() still it did not work.
>
> Any idea what is the problem?

Length(reply) == 0 means that the other side closed the socket without sending anything back.
-- 
Piet van Oostrum <piet at vanoostrum.org>
WWW: http://pietvanoostrum.com/
PGP key: [8DAE142BE17999C4]



More information about the Python-list mailing list