twisted

Close inactive connections in Twisted

大城市里の小女人 提交于 2019-12-02 08:43:26
问题 I'm running a Twisted server with the LineReceiver protocol. Sometimes clients will disconnect silently, so Twisted keeps the connection open. And because the server doesn't send anything unless requested of it, there's never a TCP timeout. In other words, some connections are never closed server-side. How can I have Twisted close a connection that's been inactive for a few hours? 回答1: You can schedule timed events using reactor.callLater . Based on this, there's a helper for adding timeouts

Twisted Python: Cannot write to a running spawned process

微笑、不失礼 提交于 2019-12-02 07:37:00
My question is, after spawning a process, the child process is looping to get data from its stdin. I would like to write new data to it using either Echo.Process.pipes[0].write(data) or Echo.Process.writeToChild(0,data), but both do not work. Would someone explain what's going on? Or how do I go around this problem? This is the error I got: --- <exception caught here> --- File "/usr/local/encap/python-2.6.4/lib/python2.6/site-packages/Twisted-9.0.0-py2.6-linux-x86_64.egg/twisted/internet/selectreactor.py", line 146, in _doReadOrWrite why = getattr(selectable, method)() File "/usr/local/encap

2 SSL certificates in twisted

梦想与她 提交于 2019-12-02 06:59:10
I had this code: from twisted.web.server import Site from twisted.web.static import Data from twisted.internet import reactor, ssl root = Data("", "text/plain") site = Site(root) reactor.listenSSL(config.ws_port, site, ssl.DefaultOpenSSLContextFactory( '/etc/apache2/ssl/wc.key', '/etc/apache2/ssl/wc.crt') ) But i have got additional domain and another certificate for it. I need working twisted with 2 certificates for each domain. How i can add second certificate for twisted? The ways TLS works with HTTP to support multiple hostnames is either by using a single certificate that contains all of

Close inactive connections in Twisted

﹥>﹥吖頭↗ 提交于 2019-12-02 05:39:11
I'm running a Twisted server with the LineReceiver protocol. Sometimes clients will disconnect silently, so Twisted keeps the connection open. And because the server doesn't send anything unless requested of it, there's never a TCP timeout. In other words, some connections are never closed server-side. How can I have Twisted close a connection that's been inactive for a few hours? You can schedule timed events using reactor.callLater . Based on this, there's a helper for adding timeouts to protocols, twisted.protocols.policies.TimeoutMixin . Another approach is to use TCP keep-alives, which

What are the ways to run a server side script forever?

╄→尐↘猪︶ㄣ 提交于 2019-12-02 03:57:04
I need to run a server side script like Python "forever" (or as long as possible without loosing state), so they can keep sockets open and asynchronously react to events like data received. For example if I use Twisted for socket communication. How would I manage something like this? Am I confused? or are there are better ways to implement asynchronous socket communication? After starting the script once via Apache server, how do I stop it running? If you are using twisted then it has a whole infrastructure for starting and stopping daemons. http://twistedmatrix.com/projects/core/documentation

Twisted Framework Server Making Connections as a Client?

拥有回忆 提交于 2019-12-02 02:00:18
So first off, let me show you my code and the error it returns: print "before import" from twisted.internet import protocol # imports print "after protocol" from twisted.internet import reactor print "after reactor" from twisted.internet.endpoints import TCP4ServerEndpoint print "after import" class Echo(protocol.Protocol): """docstring for Echo""" def connectionMade(self): cADDR = self.clnt = self.transport.getPeer().host print "...Connection made with {0}".format(cADDR) def dataReceived(self, data): self.transport.write(data) class EchoFactory(protocol.Factory): """docstring for EchoFactory"

Python-Twisted: Reverse Proxy to HTTPS API: Could not connect

爷,独闯天下 提交于 2019-12-02 01:32:57
I am trying to build a reverse-proxy to talk to certain APIs(like Twitter, Github, Instagram) that I can then call with my reverse-proxy to any (client) applications I want (think of it like an API-manager). Also, I am using an LXC-container to do this. For example, here is the simplest of code that I hacked from the examples on the Twisted Docs: from twisted.internet import reactor from twisted.web import proxy, server from twisted.python.log import startLogging from sys import stdout startLogging(stdout) site = server.Site(proxy.ReverseProxyResource('https://api.github.com/users/defunkt',

how to emit signal from a non PyQt class?

那年仲夏 提交于 2019-12-01 23:56:18
i'm programming an application in python using twisted and PyQt . the problem that i'm facing is that when a function in my twisted code is executed i have to print a line in the GUI, i'm trying to achieve this by emiting a signal (Non PyQt class). This does not seem to work, i have a doubt that the twisted event loop is screwing things for PyQt. Because the closeEvent signal is not being trapped by the program. Here's the code snippet: from PyQt4 import QtGui, QtCore import sys from twisted.internet.protocol import Factory, Protocol from twisted.protocols import amp import qt4reactor class

Twisted: disable logging of Twisted-framework classes

北战南征 提交于 2019-12-01 21:17:41
My Twisted-based client sends UDP packets in a loop. Therefore I'm using the class DatagramProtocol. This is the source: #!/usr/bin/python # -*- coding: utf-8 -*- from twisted.application.service import Service from twisted.internet import reactor from twisted.internet.task import LoopingCall from twisted.internet.protocol import DatagramProtocol from twisted.python import log import logging class HeartbeatClient(Service): def __init__(self, host, port, data, beat_period): self.ip = host self.port = int(port) self.data = data self.beat = int(beat_period) def startService(self): self._call =

Odd Behavior when Connecting to my Program

穿精又带淫゛_ 提交于 2019-12-01 19:47:41
I'm using Twisted to implement a server, of sorts. When I test it, the first line it receives is always strange: Starting Server... New connection from 192.168.1.140 192.168.1.140: ÿûÿû ÿûÿû'ÿýÿûÿý\NAME Blurr 192.168.1.140: \NAME Blurr (for both inputs I sent \NAME Blurr .) This is the code that prints the input: def lineReceived(self, line): print "{0}: {1}".format(self.name, line) I'm connecting via Putty through Telnet to a remote host. Is this a telnet protocol I'm missing, or what? When I use Unix's telnet program and connect locally, the first line is fine. You can find an explanation of