twisted

Sending arbitrary data with Twisted

自古美人都是妖i 提交于 2019-12-11 02:58:54
问题 An example of my code is as follows. I would like to arbitrarly send data at various points in the program. Twisted seems great for listening and then reacting, but how to I simply send data. from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor import os class listener(DatagramProtocol): def __init__(self): def datagramReceived(self, data, (host, port)): print "GOT " + data def send_stuff(data): self.transport.write(data, (host, port)) reactor.listenUDP

Search devices on all networks

旧城冷巷雨未停 提交于 2019-12-11 02:54:30
问题 I want to implement a code through which i can list-up upnp compliant media renderer devices connected on network. I googled for this and found following code on twisted website When 2 networks(ethernet and wifi) are connected on my machine, it lists up devices of only one network. code from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor import re class MulticastPingPong(DatagramProtocol): XMLNS = "{urn:schemas-upnp-org:device-1-0}" def startProtocol

Is this python code thread safe (thread with twisted)?

大憨熊 提交于 2019-12-11 02:39:44
问题 I am writing an application to collect UDP messages and process them every 1sec. Application prototype looks like: from twisted.internet.protocol import DatagramProtocol from twisted.internet import reactor import threading import time class UdpListener(DatagramProtocol): messages = [] def datagramReceived(self, data, (host, port)): self.messages.append(data) class Messenger(threading.Thread): listener = None def __init__(self): threading.Thread.__init__(self) def run(self): while True: time

Twisted Python: Max Packet Size? Flush socket?

风格不统一 提交于 2019-12-11 01:45:49
问题 I'm implementing a client-server solution based on Twisted for the server side and e.g. and Android phone for the client side. Because the Andoird emulator takes no TCP Packets larger then 1500b (or less?), I need to be able to chunk packets on the server side. Without flushing the socket after each "transport.write", Twisted buffers the outgoing data so the chunking would be useless without somekind of manual or automatic flushing / maxpacketsize function. How do I do this in Twisted? I'm

Send multiple messages to server from twisted client

假装没事ソ 提交于 2019-12-11 01:37:03
问题 I'm trying to build a client/server system that clients send messages to server. Server does nothing more than printing out what clients send. from twisted.internet import protocol, reactor class Echo(protocol.Protocol): def dataReceived(self, data): print data self.transport.write(data) class EchoFactory(protocol.Factory): def buildProtocol(self, addr): return Echo() reactor.listenTCP(8000, EchoFactory()) reactor.run() The issue is that when I tried to send multiple message from client with

Twisted HTTPS Client

眉间皱痕 提交于 2019-12-10 23:24:00
问题 I am currently having some trouble accessing content hosted via https using the twisted python library. I am new to this library, and am assuming there is some concept I am missing that's causing the issue, but perhaps not based upon the example. Here is a link to the page in which I gathered the example: https://twistedmatrix.com/documents/current/web/howto/client.html Under the heading HTTP over SSL from twisted.python.log import err from twisted.web.client import Agent from twisted

How to catch unhandled error in Deferred originating from reactor.stop()

余生长醉 提交于 2019-12-10 22:45:21
问题 I am new to twisted and having trouble with the following script. When I run the following: #!/usr/bin/env python from twisted.internet import defer from twisted.web.client import getPage, reactor def success(results): print 'success' def error(results): print 'error' return results def finished(results): print 'finished' reactor.stop() tasks = [] d = getPage('thiswontwork').addCallback(success).addErrback(error) tasks.append(d) dl = defer.DeferredList(tasks) dl.addCallback(finished) reactor

Has Twisted changed its dependencies?

给你一囗甜甜゛ 提交于 2019-12-10 21:28:37
问题 I'm currently working on a Python/Twisted project which is to be distributed and tested on Planetlab. For some reason my code was working on friday and now that I wanted to test a minor change it refuses to work at all: Traceback (most recent call last): File "acn_a4/src/node.py", line 6, in <module> from twisted.internet.protocol import DatagramProtocol File "/usr/lib/python2.5/site-packages/Twisted-10.0.0-py2.5-linux-i686.egg/twisted/__init__.py", line 18, in <module> from twisted.python

how to kill twisted protocol instances python

a 夏天 提交于 2019-12-10 21:24:27
问题 I have a server application written in python using twisted and I'd like to know how to kill instances of my protocol (bottalk). Everytime I get a new client connection, I see the instance in memory (print Factory.clients) .. but let's say I want to kill one of those instances from the server side (drop a specific client connection)? Is this possible? I've tried looking for a phrase using lineReceived, then if it matches, self.transport.loseConnection(). But that doesn't seem to reference the

twistd using usage.options in a *.tac file

痴心易碎 提交于 2019-12-10 19:10:59
问题 I'm writing a server with Twisted that is based on a *.tac file that starts the services and the application. I'd like to get one additional command line argument to specify a yaml configuration file. I've tried using usage.Options by building a class that inherits from it, but is choking because of the additional, twistd command line arguments (-y for example) not being specified in my class Options(...) class. How can get one additional argument and still pass the rest to twistd? Do I have