twisted

twisted not detecting client disconnects

时光怂恿深爱的人放手 提交于 2019-12-06 05:09:34
问题 Does anybody have experience with this? I have a twisted app. The clients connect to the server. I added a feature so that if a client connects to a server, but there's already a client from that IP address running, it disconnects the new client. Once in a while, I shutdown a client computer (or VM, to be precise) without manually turning off the Python program. When I do this, once in a while but pretty often, the server does not detect any disconnect. When the computer comes back up and

Twisted Python getPage

坚强是说给别人听的谎言 提交于 2019-12-06 05:05:46
问题 I tried to get support on this but I am TOTALLY confused. Here's my code: from twisted.internet import reactor from twisted.web.client import getPage from twisted.web.error import Error from twisted.internet.defer import DeferredList from sys import argv class GrabPage: def __init__(self, page): self.page = page def start(self, *args): if args == (): # We apparently don't need authentication for this d1 = getPage(self.page) else: if len(args) == 2: # We have our login information d1 = getPage

twisted location header redirect

邮差的信 提交于 2019-12-06 04:41:38
From the render_GET method of a Resource in twisted , is it possible to redirect to a different url entirely (hosted elsewhere) request.redirect(url) doesn't appear to do anything, and neither does twisted.web.util.Redirect The equivalent in php would be, header('location:'.$url); EDIT this is the code I'm running from twisted.web import server, resource from twisted.internet import reactor class Simple(resource.Resource): isLeaf = True def render_GET(self, request): request.redirect("www.google.com") request.finish() site = server.Site(Simple()) reactor.listenTCP(8080, site) reactor.run() I

Using PythonAnywhere as a game server

可紊 提交于 2019-12-06 01:30:14
I'm building a turn-based game and I'm hoping to implement client-server style networking. I really just need to send the position of a couple of objects and some other easily encodable data. I'm pretty new to networking, although I've coded some basic stuff in socket and twisted. Now, though, I need to be able to send the data to a computer that isn't on my local network, and I can't do port forwarding since I don't have admin access to the router and I'm also not totally sure that would do the trick anyways since I've never done it. So, I was thinking of running some Flask or Bottle or

06-01 Scrapy框架

只谈情不闲聊 提交于 2019-12-06 01:12:28
06-01 Scrapy框架 一 介绍 Scrapy一个开源和协作的框架,其最初是为了页面抓取 (更确切来说, 网络抓取 )所设计的,使用它可以以快速、简单、可扩展的方式从网站中提取所需的数据。但目前Scrapy的用途十分广泛,可用于如数据挖掘、监测和自动化测试等领域,也可以应用在获取API所返回的数据(例如 Amazon Associates Web Services ) 或者通用的网络爬虫。 Scrapy 是基于twisted框架开发而来,twisted是一个流行的事件驱动的python网络框架。因此Scrapy使用了一种非阻塞(又名异步)的代码来实现并发。整体架构大致如下 The data flow in Scrapy is controlled by the execution engine, and goes like this: The Engine gets the initial Requests to crawl from the Spider . The Engine schedules the Requests in the Scheduler and asks for the next Requests to crawl. The Scheduler returns the next Requests to the Engine . The Engine

Receiving commandline input while listening for connections in Python

僤鯓⒐⒋嵵緔 提交于 2019-12-06 00:45:42
问题 I am trying to write a program that has clients connect to it while the server is still able to send commands to all of the clients. I am using the "Twisted" solution. How can I go about this? Here is the code I have so far (I understand that Twisted already uses non-blocking sockets): import threading print 'threading.' def dock(): try: from twisted.internet.protocol import Factory, Protocol from twisted.internet import reactor import currentTime print '[*]Imports succesful.' except: print '

Unable to install twisted package on windows machine

梦想的初衷 提交于 2019-12-05 23:33:17
问题 I have got python2.6 installed on my windows machine. tried to install twisted package but unable to install it. Also installed the zope interface On the python interpretor I get the error as : >>>import twisted >>>Import Error: No Module named twisted I installed the package twisted succesfully. C:\Documents and Settings\tazim_kolhar>python Python 2.6 (r26:66721, Oct 2 2008, 11:35:03) [MSC v.1500 32 bit (Intel)] on win 32 Type "help", "copyright", "credits" or "license" for more information.

Testing twisted protocol

早过忘川 提交于 2019-12-05 23:18:40
I have a very basic client and server protocols developed using Twisted . Twisted allows to unittest them independently and provides nice testing utils such as the StringTransport for this. However, let's say I want to test the protocol works fine. For instance, I want to test that when the server receives a certain message, it will reply to the client in some specific way. What is the best way to do that using trial and the utils in Twisted? I am currently launching processes to run them, but then I lose the access to their objects and I need to dump their states in a file to validate the

Twisted: number of client connections to TCP server limited?

我们两清 提交于 2019-12-05 20:25:39
I'm writing a chat server and encountered the following problem while unit testing it. In one of my unit tests, I connect many test clients to my server. As the number of connected users get to 511 the server stops responding without any error message. At this stage everything runs locally on a PC. I have prepared a simple server, test client and unit test code to paste into the forum. Any idea why the server hangs up? Any help is much appreciated This code is basicly from the twisted simple chat tutorial. Simple server: from twisted.internet.protocol import Factory from twisted.protocols

How to limit the number of simultaneous connections in Twisted

三世轮回 提交于 2019-12-05 19:38:35
so I have a twisted server I built, and I was wondering what is the best way to limit the number of simultaneous connections? Is having my Factory return None the best way? When I do this, I throw a lot of exceptions like: exceptions.AttributeError: 'NoneType' object has no attribute 'makeConnection' I would like someway to have the clients just sit in queue until the current connection number goes back down, but I don't know how to do that asynchronously. Currently I am using my factory do like this: class HandleClientFactory(Factory): def __init__(self): self.numConnections = 0 def