Broken pipe

Chris Rebert clp2 at rebertia.com
Fri May 7 01:37:14 EDT 2010


On Thu, May 6, 2010 at 10:27 PM, cerr <ron.eggler at gmail.com> wrote:
> Hi There,
>
> I'm very new to Python and i wanna write a script that sends a certain
> string to a server. The code I came up with looks like this:
> #!/usr/bin/python
>
> import sys
> import string
>
> from socket import *
> usage="USAGE: "+sys.argv[0]+" <server> <port>";
> if len(sys.argv) != 3:
>              print usage;
>              sys.exit(0);
> host = sys.argv[1];
> port = sys.argv[2];
> buf = 1024;
> addr = (host,port);
> sock = socket(AF_INET, SOCK_STREAM);
> data = string.join("NovaxTest",'\n');
> sock.send(data);
> sock.close();
> and I'm calling this script like that: "./TestService.py 127.0.0.1
> 1514" but when I call it I get following back:
> sending data to 127.0.0.1:1514
> data: NovaxTest
> Traceback (most recent call last):
>  File "./TestService.py", line 18, in <module>
>    sock.send(data);
> socket.error: [Errno 32] Broken pipe
> I understand that UNIX sends an Errno32 if the server closes the
> connection. But if i telnet to localhost on 1514 and send NovaxTest by
> hand everything works just fine. So what might be wrong here?

You never called sock.connect(addr). Your code doesn't even use `addr` at all.
Also, please don't use semicolons in your code. It's bad style.

Cheers,
Chris
--
http://blog.rebertia.com



More information about the Python-list mailing list