python socket query

smilesonisamal at smilesonisamal at
Mon Dec 23 04:05:38 CET 2013

   I am trying to write a TCP socket program in python. I am using python 2.6 in linux. 

I referred following link:
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))


reply = s.recv(2**14)


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?



More information about the Python-list mailing list