[Tutor] sockets

Brendon bren@europe.nl.com
Tue, 3 Jul 2001 00:06:15 +0200


On Monday 02 July 2001 22:05, you wrote:
> > 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.
>

well, just one last question before i dive into the docs. i was wondering how 
i could write all the data recieved from socket to a file. i.e.

#------------------------
# Echo client program
import socket

HOST = 'jabber.org'    # The remote host
PORT = 5222            # The same port as used by the server

s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
s.connect((HOST, PORT))

loginData = '<?xml version="1.0" encoding="UTF-8" ?><stream:stream  
to="jabber.org"  xmlns="jabber:client"   
xmlns:stream="http://etherx.jabber.org/streams">'

s.send(loginData)
data = s.recv(1024)

s.close()
print 'Received', data
#-------------------------
the statement "data = s.recv(1024)" apparently causes the first 1024 
characters to be assigned to 'data', but because eventually it'll go over the 
limit i want it to write every packet to a file which can be queried later. 

how do i go about this? 
-- 

"if we live by an "eye for an eye and a tooth for a tooth"...before long, 
the whole world will be blind and toothless." 
         --Tevye, Fiddler on the Roof