开发者

Connect Twisted IRCClient through a http proxy

开发者 https://www.devze.com 2023-04-09 06:43 出处:网络
I am playing around with Twisted and while trying to rewrite an old java IRC bot in Python (2.7), I built upon the IrcLogBot example.

I am playing around with Twisted and while trying to rewrite an old java IRC bot in Python (2.7), I built upon the IrcLogBot example.

I need to connect to the IRC server through a (non auth) HTTP proxy - but there does not seem to be any support for this neither in the irc.IRCClient or in reactor.connectTCP. Am I looking in the wrong places? Can I wrap my connection in some kind of proxy tunneler?

Th开发者_开发问答anks in advance for any help!


If the HTTP proxy you are connecting to supports CONNECT requests, this is totally doable.

Here is an example that works for tunneling SSH connections over an HTTP proxy. It should work for IRC connections as well.

With the example code, you should be able to do something like:

proxy = HTTPProxyConnector('myhttpproxy.server', 8080)
proxy.connectTCP('myirc.server', 6667, MyTwistedIRCClientFactory())

There are still some issues to work out with handling server timeouts more gracefully / quickly, but if you include some kind of periodic application or underlying protocol-level ping, it should keep both servers from timing out your connection.

0

精彩评论

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

关注公众号