By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
440,965 Members | 1,757 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 440,965 IT Pros & Developers. It's quick & easy.

Twisted server and protocol question

P: n/a
Hi guys. I hope I can discuss Twisted here. If not, direct me to the
correct place please.

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.

Aug 28 '06 #1
Share this Question
Share on Google+
1 Reply


P: n/a

Benry wrote:
Hi guys. I hope I can discuss Twisted here. If not, direct me to the
correct place please.
Twisted mailing list:
http://twistedmatrix.com/cgi-bin/mai...twisted-python

;-)
~Simon

Aug 28 '06 #2

This discussion thread is closed

Replies have been disabled for this discussion.