On Thu, May 6, 2010 at 11:11 PM, Ron Eggler <ron.egg...@gmail.com> wrote: > On May 6, 2010 10:37:14 pm Chris Rebert wrote: >> On Thu, May 6, 2010 at 10:27 PM, cerr <ron.egg...@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 :$ <snip> > 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 <snip> > 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 -- http://blog.rebertia.com -- http://mail.python.org/mailman/listinfo/python-list