[Twisted-Python] Help implement protocol
Keith Cheung (張國良)
keith.cheung at lkmachinery.com.hk
Fri Aug 4 21:44:44 MDT 2006
Hi all,
I want to implement some handshake protocol, say..
1. Client: WhatDate
2. Server: 5Aug
3. Client: WhatYear
4. Server: 2006
5. Client: WhatTime
6. Server: 1005
So, for the client:- (pseudo code)
def connectionMade():
send "WhatDate"
state = askingForDate
def lineReceived(data):
switch state:
askingForDate:
date = data
send "WhatYear"
state = askingForYear
break
askingForYear:
year = data
send = "WhatTime"
state = askingForTime
break
askingForTime:
time = data
state = initialState
disconnect
The switch case becomes gigantic as the protocol grow. Instead of keeping states, are there better ways to implement?
More information about the Twisted-Python
mailing list