Code Monkey home page Code Monkey logo

Comments (2)

fiorix avatar fiorix commented on July 23, 2024

Perhaps that's because it's making a new connection to mongo on each udp received.
Consider something like the below, which will set up a mongo connection on demand on the first udp:

class Collector(DatagramProtocol):
def init(self):
self.db = None

@defer.inlineCallbacks                                                       
def datagramReceived(self, data, (host, port)):                              
    if self.db is None:                                                      
        self.db = yield txmongo.MongoConnection()                            

    # then use self.db for everything                                        
    # ...                                                                    

On 2012-05-29, at 1:23 PM, James Jones wrote:

from twisted.internet.protocol import DatagramProtocol
from twisted.internet import reactor,defer
import txmongo
import struct
import string

x = 0

class Collector(DatagramProtocol):
def init(self):
print "Initializing Collector";

@defer.inlineCallbacks
def datagramReceived(self, data, (host, port)):
#print "Recieved Packet"
ch = yield txmongo.MongoConnection()
dbh = ch.flowpackets.packets
#print "received %r from %s:%d type:%s" % (data, host, port,type(data))
#self.transport.write(data, (host, port))
global x
packet = dict()
packet = { 'packet': data.encode('hex')}
dbh.insert(packet)
x += 1

reactor.listenUDP(2055, Collector())
print "Starting Reactor"
reactor.run()
print "Packet Count: ", x

Ship, ahoy! Hast seen the White Whale?

  • Cap'n Ahab

from txmongo.

outcast avatar outcast commented on July 23, 2024

Sounds like a plan will try that.

from txmongo.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.