[Twisted-Python] Newb question?

Benjamin Henry bhenry at pacecocorp.com
Mon Aug 28 17:52:59 EDT 2006


My question(s): 
I'm working on a custom network protocol (application layer in TCP/IP 
model) for a custom network.  Please don't try to talk me out of this. 
I'm limiting many of the other protocols, because this is in a highly 
secure network, and latency/bandwidth is key.  The packet sizes are 
minimized by the protocol design, which is ideal.  Anyway.  I'm having 
some problems with figuring out what to include in the Protocol class, 
and what to handle in the server class.  Basically, I'm using Telnet, 
SMTP, and FTP protocol python files as a reference, and each have 
different strutures and methods of doing similar things.  Basically, 
the protocol I'm developing is very similar to Telnet, so I used this 
code as a base.  It is necessary to have a state machine, but there is 
dynamic information to send as a response to some received messages. 
For example, the server may need to get information from a DB, and send 
it in a packet as a reponse to a request.  I'll give you a sample 
implementation, and the remainder of the specific questions below: 

server = a 
client = b 

1a = NEED, 1   - NEED is a request to send data from client to server, 
1 is the option, or type of data 
2b = HAVE, 1   - HAVE is a positive response 
3a = NEED, 1   - re-iterated for the purpose of being a server.  The 
line "1a" is initiated only by a UI command.  The line "3a" is 
initiated by as a response to the request "2b". 
4b = PASV, 1  - same as FTP.  It's basically, "Well, I have data...what 
port can I send it on?" 
4a = PORT, 1, 51000 - not the same as FTP.  It's the command, option, 
and port number 
5b = ACK       - acknowledge 
ok...now they both disconnect, or stop communication on this port, and 
server dynamically opens port 51000 
on port 51000: 
6b - <<data stream>> 
7a - <<md5 or something other to verify correct and complete>> 

Questions I have: 
This is a state machine.  The server has a class derived from the 
Protocol class whose methods are called prior to the Protocol's.  For 
example, since the Server is using the derived Protocol class (let's 
say it's PProto), whenever a "dataReceived" is fired, PProto picks it 
up, and has to call Protocol's dataReceived handler explicitly.  Where 
should all of this message handling take place?  Should I split up the 
duties, like anything that's a singular response to one line should be 
in the Protocol class, and anything dynamic can be in the PProto class? 

What about dynamic ports?  Where should this be implemented?  The 
alternative is to have many connections on the one server port.  Would 
this cause any issues, so that I could eliminate the PASV command 
altogether? 

I need to read the data being sent by the client.  How can I correctly 
intercept this data without effecting the operation of the Protocol, 
and also so I can port the Protocol class to other applications without 
rewriting the server? 

I'm a newbie :). 

Thanks for your help. 

 

-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://twistedmatrix.com/pipermail/twisted-python/attachments/20060828/ab70fd5c/attachment.htm 


More information about the Twisted-Python mailing list