Broken pipe

C

cerr

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?

Thank you very much!
Ron
 
C

Chris Rebert

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
 
R

Ron Eggler

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
 
C

Chris Rebert

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 :$
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
What does that mean? :(

You never converted `port` to an int, it's still a string.

You might consider reading the socket module docs:
http://docs.python.org/library/socket.html

Cheers,
Chris
 
R

Ron Eggler

--
Ron Eggler
Suite# 1804
1122 Gilford St
Vancouver, BC V6G 2P5
Canada
(778) 230-9442
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 :$

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

What does that mean? :(

You never converted `port` to an int, it's still a string.

port = int(sys.argv[2])

doesn't seem to help it either :(
You might consider reading the socket module docs:
http://docs.python.org/library/socket.html

mh, i browsed through it but didn't quite find what i'm looking for, do you
have any more hints?

Thanks,
Ron
 
C

cerr

--
Ron Eggler
Suite# 1804
1122 Gilford St
Vancouver, BC V6G 2P5
Canada
(778) 230-9442




On May 6, 2010 10:37:14 pm Chris Rebert 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 :$
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
What does that mean? :(
You never converted `port` to an int, it's still a string.

port = int(sys.argv[2])

doesn't seem to help it either :(


You might consider reading the socket module docs:
http://docs.python.org/library/socket.html

mh, i browsed through it but didn't quite find what i'm looking for, do you
have any more hints?
Ah, okay, I figured that out! I actually just needed to add a \n at
the end to signal the server that this is the end of the line. All
good now, thanks for your help!
 
L

Lie Ryan

Wonder why they’re allowed, then.

they're there for line continuation, e.g.:

a = 40; foo(a)

but in many cases, putting two statements in a single line reduces
readability so use the semicolons extremely conservatively. But the
worst is the abuse of semicolons for end-of-line markers.
 
L

Lawrence D'Oliveiro

they're there for line continuation, e.g.:

a = 40; foo(a)

but in many cases, putting two statements in a single line reduces
readability so use the semicolons extremely conservatively. But the
worst is the abuse of semicolons for end-of-line markers.

So why are they allowed, then?
 
L

Lie Ryan

So why are they allowed, then?

Convenience. I've sometimes, in the interactive interpreter, written
codes that looks like:

a = 0; ... other code ...

since I need to reset the variable 'a' every time 'other code' is run.
If there hasn't been the ;, then I'd have to press up, up, enter, up,
up, change, enter. Compare that to up, change, enter since I can "up"
two "lines" at once.

In the interactive interpreter these sort of conveniences is often useful.

Unless your "why are they allowed" is about why a blank continuation
(i.e. abusing ; as line ending) is allowed. In that case, I'd presume
it's just because conceptually:

foo();
bar

is just:

foo()

bar()


but probably you're right; maybe they should be strictly disallowed. But
it's too late for this kind of change, not until py4k.
 
D

Dennis Lee Bieber

So why are they allowed, then?

Semicolon is a statement SEPARATOR -- but so is a NEWLINE.

Some languages (see C and Ada) use semicolon as a statement
TERMINATOR (and newline does not end a statement).

The epitomy of the confusion is Pascal, where a block looking like:

if...then
begin
statement1;
statement2;
end;

actually has THREE statements -- the third statement is a Nil. The
correct (or acceptable) version would be:

if...then
begin
statement1;
statement2
end;


Ada uses it as a terminator, so the following is valid:

if ... then
state
ment
1;
state
ment
2;
end if;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,968
Messages
2,570,149
Members
46,695
Latest member
StanleyDri

Latest Threads

Top