python socket query
smilesonisamal at gmail.com
smilesonisamal at gmail.com
Sun Dec 22 22:05:38 EST 2013
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?
Regards
Pradeep
More information about the Python-list
mailing list