[Tutor] What's wrong with this?
Ali Polatel
alipolatel at yahoo.com
Fri Aug 13 12:07:14 CEST 2004
Dear Friends and Tutors,
Thanx for all your previous answers I have a new problem
I am writing a python script which will connect to Internet Chess Club via telnet(the IP of the server is '65.245.208.34' and the port I want is 5056)
Connecting works fine :
"import telnetlib
telnetlib.Telnet(host='65.245.208.34',port='5056')"
Now the server asks for username and password...
I want the programme to login as guest so :
"a=telnetlib.Telnet(host='65.245.208.34',port='5056')
a.read_until('login:')
a.write('guest \n')"
Now programme is connected to the server.Now I want to type commands and such things...Before I write a command I should do
"a.read_until('aics%')"
to get the command line.
But the problem starts here.Some announces and chats come from the server and the server seems like that
"xxx shouts: hi all
aics%
bbb shouts:hi again
aics%_"
The real command line is the second "aics%" but the programme types "a.read_until('aics%') only once so that when I type in a command programme doesn't send the command to the server.
So I should make the programme type "a.read_until('aics%')" every 5 seconds or so...
Can anyone show me how and where to do this change?
Below is the script :
"def icc():
a=telnetlib.Telnet(host='65.245.208.34',port='5056')
print str(a.read_until('login:'))
a.write('guest')
a.write('\n')
a.read_until('aics%')
a.write('-ch 1\n')
a.read_until('aics%')
a.write('-ch 165\n')
a.read_until('aics%')
a.write('set shout 0\n')
a.read_until('aics%')
a.write('set sshout 0\n')
a.read_until('aics%')
print str(a.read_until('aics%'))
for x in range(500000):
d=raw_input(Command :>')
a.write(str(d))
a.write('\n')
print str(a.read_until('aics%'))
Regards,
Ali Polatel
---------------------------------
Do you Yahoo!?
Yahoo! Mail is new and improved - Check it out!
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.python.org/pipermail/tutor/attachments/20040813/2f0a7cf2/attachment.htm
More information about the Tutor
mailing list