Broken pipe

Ron Eggler ron.eggler at gmail.com
Fri May 7 02:11:22 EDT 2010


On May 6, 2010 10:37:14 pm Chris Rebert wrote:
> 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. 
Oh, yeah, hOOps :$

> Also, please don't use semicolons in your code. It's bad style.
Is it, eh? Well, I'm from C, C++ and for me it just belongs there..:) but i'll 
try to change my habits... :)

Hm weird now I get something like:
Traceback (most recent call last):
  File "./TestService.py", line 14, in <module>
    sock.connect((host,port))
  File "<string>", line 1, in connect
TypeError: an integer is required


with this code:

#!/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]
sock = socket(AF_INET, SOCK_STREAM)
sock.connect((host,port))
data = string.join("NovaxTest",'\n')
sock.send(data)
sock.close()

What does that mean? :(

Thanks,
Ron



More information about the Python-list mailing list