[Tutor] sockets

Allan Crooks allan.crooks@btinternet.com
Mon, 02 Jul 2001 21:05:42 +0100


> with the following code:
> 
> import sys
> import socket
> 
> s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
> 
> loginPacket = '<?xml version="1.0" encoding="UTF-8" ?><stream:stream 
> to="jabber.org" xmlns="jabber:client" 
> xmlns:stream="http://etherx.jabber.org/streams">'
> 
> s.send(loginPacket)
>     	
> data = s.recv(1024)
> s.close()
> print "Recieved", data
> ----
> 
> i get the error message: s.send(loginPacket) socket.error: (32, 'Broken 
> pipe'). any clue what i'm doing wrong?

I'd suggest taking a look at http://www.python.org/doc/current/lib/socket-example.html.

The problem is, you create the socket, but then you aren't connecting it to a particular address. Where exactly are you aiming to send the packet to? Since you aren't telling it, it's not getting sent anywhere...

At a guess, you want to send it back to the same machine. The URL I provided gives an example of how to do this....

Allan.