开发者

Twisted Matrix and telnet server implementation

开发者 https://www.devze.com 2022-12-31 12:29 出处:网络
I have 开发者_运维技巧a project which is essentially a game server where users connect and send text commands via telnet.

I have 开发者_运维技巧a project which is essentially a game server where users connect and send text commands via telnet.

The code is in C and really old and unmodular and has several bugs and missing features. The main function alone is half the code.

I came to the conclusion that rewriting it in Python, with Twisted, could actually result in faster completement, besides other benefits.

So, here is the questions: What packages and modules I should use? I see a "telnet" module inside "protocols" package. I also see "cronch" package with "ssh" and another "telnet" module.

I'm a complete novice regarding Python.


Greg's suggestion to try to become familiar with Python before trying to take on Twisted is perhaps a reasonable one. Limiting the possible sources of your confusion may help you avoid some very frustrating cases.

On the other hand, I know a lot of people who take on a Twisted-based project as a first Python learning experience, and succeed. So it's possible. And you'll have to do something first. There's no guarantee that what you pick instead of Twisted will be easier. :)

As far as the specifics of telnet go, you want to use twisted.conch.telnet, not twisted.protocols.telnet. The former is newer, better tested, more featureful, and has several examples (although unfortunately not a lot of documentation beyond that).

The main telnet example shows you the most useful event handlers you can define if you use twisted.conch.telnet. Unfortunately it doesn't really explain what they do, nor does it give a demonstration of how you might negotiation options. If you're already familiar with the telnet protocol itself (primarily the option negotiation part of it), this should make sense to you. If you're thinking of "telnet" as just a way to pass human readable/writeable bytes between two computers, then you probably haven't run across option negotiation before and it might not make much sense. You can either ignore it, or check out the telnet RFC to learn more (it's a little dense, though).

For performing option negotiations yourself, you can at least take a look at the API documentation for the self.transport object you see in the above linked example (this isn't a regular TCP transport as you'll find used throughout much of Twisted, but a special telnet-derived transport which sits on top of TCP, so it has a few extra features).

If you just want to pass bytes around, though, then you can focus on the dataReceived method and on self.transport.write. The former will be called when you receive bytes from your peer; the latter you can call to send bytes to your peer.


It sounds like you've got two separate tasks here:

  • Port the code from C to Python.
  • Rewrite the whole program to use Twisted.

Since you're new to Python, I would be inclined to do the first one first, before trying to make the program structure work in Twisted. If the program is old, there isn't likely to be any performance problems running it on modern hardware.

Converting the C code to Python first will give you the familiarity with Python you need to start on the port to Twisted.

0

精彩评论

暂无评论...
验证码 换一张
取 消