Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Twisted server and protocol question

Thread Tools

Twisted server and protocol question

Posts: 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 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

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.

Reply With Quote
Simon Forman
Posts: 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:


Reply With Quote

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Re: [Twisted-Python] Twisted 13.0.0 released Glyph Python 0 04-03-2013 09:36 PM
Re: [Twisted-Python] Twisted 12.3.0 released Glyph Python 0 12-27-2012 06:40 AM
Re: [Twisted-Python] Re-working a synchronous iterator to use Twisted Jean-Paul Calderone Python 0 06-17-2008 10:14 PM
Protocol Chart - Learn how to use a Protocol Analyzer Wireless Networking 0 08-21-2004 04:35 PM
When i try to implement a server program giving UDP as protocol , it works fine , but if the same code is executed with TCP as protocol option, it gives an error. Tompyna Perl Misc 4 02-17-2004 06:51 PM