python socket query
rosuav at gmail.com
Mon Dec 23 04:19:30 CET 2013
On Mon, Dec 23, 2013 at 2:05 PM, <smilesonisamal at gmail.com> wrote:
> 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
First off, your formatting has become mangled. This is likely to be
because of Google Groups, which tends to make a mess of posts. I
strongly recommend you get a better newsreader, such as Thunderbird,
or switch to the mailing list:
I'm going to assume that (a) the code you've provided is all part of
the tcp() function, and (b) that you are actually calling tcp()
somewhere and seeing what comes back. But once you sort out your
posting issues, you may want to post a complete program (probably not
more than a couple of additional lines beyond what you have above) so
we know what's actually going on.
Terminology point: You mention binding to the socket. In networking,
"bind" has a specific meaning - binding to an address, usually done
for servers, and something you're not doing here.
Are you sure the server's doing something? I tried what you had there
(albeit under Python 3.3), and it seems to be fine. Perhaps you need
to terminate the request with something - maybe a newline. The send()
method will send exactly the bytes you give it, nothing more.
Can you telnet to the server?
More information about the Python-list