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

Jochen Haeberle listen@MIDRAS.de
Thu, 3 Feb 2000 21:30:01 +0100


Hi,

I m trying to do the first thing in python. I would like to query the
OANDA currency server for some exchange rates. I wanted to do a
simple script, modify it in some methods and form a class for
starters, as I am also beginning with OOP.

But I can't get it to work at all!

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

The following script does not produce _anything_ in data :-( Is my
simple client so wrong or is there anything with Oanda I am not aware
of??

Where can I learn about doing easy network/socks clients?

# Currency Fetcher - fetch a conversion unit from OANDA
from socket import *
HOST = 'www.oanda.com'
PORT = 5011

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

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


Jochen