[Tutor] First python-script: a little network client

Deirdre Saoirse deirdre@deirdre.net
Thu, 3 Feb 2000 13:57:18 -0800 (PST)

On Thu, 3 Feb 2000, Jochen Haeberle wrote:

> The protocoll specs for fxp is at
> <http://www.oanda.com/site/fxp/protocol.html>, case someone's
> interested.

There's several problems with your implementation:

1) each request is supposed to be followed by a carriage return and line
feed. This is \r\n, not \n.

2) sock.close should be sock.close()

3) after sending the headers, you have to send a blank line before
receiving data.

Given the changes mentioned above, the following works though the server
doesn't like the currency:

from socket import *
HOST = 'www.oanda.com'
PORT = 5011

sock = socket(AF_INET, SOCK_STREAM)
sock.connect(HOST, PORT)
sock.send('Query: quote\r\n')
sock.send('Quotecurrency: SFR\r\n')
sock.send('Basecurrency: EUR\r\n')

print 'Response:'
while 1:
        data = sock.recv(1024)
        print data
        if not data: break

_Deirdre   *   http://www.linuxcabal.net   *   http://www.deirdre.net
"Mars has been a tough target" -- Peter G. Neumann, Risks Digest Moderator
"That's because the Martians keep shooting things down." -- Harlan Rosenthal
<Harlan.Rosenthal@Dialogic.com>, retorting in Risks Digest 20.60