Merge pull request #9 from CodePanter/master
Moved the 'gevent' and 'pygame' imports and the 'PixelVloedServer' cl…
This commit is contained in:
commit
2bc9ff5ca4
1 changed files with 26 additions and 25 deletions
51
vloed.py
51
vloed.py
|
|
@ -8,20 +8,10 @@ code from https://github.com/defnull/pixelflut/
|
||||||
__version__ = 0.3
|
__version__ = 0.3
|
||||||
__author__ = "Jan Klopper <jan@underdark.nl>"
|
__author__ = "Jan Klopper <jan@underdark.nl>"
|
||||||
|
|
||||||
# import gevent monkeypatching and perform patch_all before anything else to
|
|
||||||
# avoid nasty eception on python closing time
|
|
||||||
from gevent import spawn, monkey
|
|
||||||
monkey.patch_all()
|
|
||||||
|
|
||||||
import pygame
|
|
||||||
from pygame import locals as pygamelocals
|
|
||||||
import struct
|
import struct
|
||||||
import time
|
import time
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
from gevent.server import DatagramServer
|
|
||||||
from gevent.queue import Queue
|
|
||||||
|
|
||||||
UDP_IP = "127.0.0.1"
|
UDP_IP = "127.0.0.1"
|
||||||
UDP_PORT = 5005
|
UDP_PORT = 5005
|
||||||
DISCOVER_PORT = 5006
|
DISCOVER_PORT = 5006
|
||||||
|
|
@ -173,21 +163,6 @@ class Canvas(object):
|
||||||
"""Clean up any sockets we created"""
|
"""Clean up any sockets we created"""
|
||||||
self.broadcastsocket.close()
|
self.broadcastsocket.close()
|
||||||
|
|
||||||
class PixelVloedServer(DatagramServer):
|
|
||||||
"""PixelVloed server class"""
|
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
|
||||||
"""Set up some vars for this instance"""
|
|
||||||
self.queue = Queue()
|
|
||||||
pixelcanvas = Canvas(self.queue, kwargs['options'])
|
|
||||||
__request_processing_greenlet = spawn(pixelcanvas.CanvasUpdate)
|
|
||||||
del (kwargs['options'])
|
|
||||||
DatagramServer.__init__(self, *args, **kwargs)
|
|
||||||
|
|
||||||
def handle(self, data, _address):
|
|
||||||
"""Is called by the DataGramServer whenever an udp package is received"""
|
|
||||||
self.queue.put(data)
|
|
||||||
|
|
||||||
class PixelVloedClient(object):
|
class PixelVloedClient(object):
|
||||||
"""Sets up a client
|
"""Sets up a client
|
||||||
|
|
||||||
|
|
@ -326,6 +301,32 @@ def RunServer(options):
|
||||||
options=options).serve_forever()
|
options=options).serve_forever()
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
|
# import gevent monkeypatching and perform patch_all before anything else to
|
||||||
|
# avoid nasty eception on python closing time
|
||||||
|
from gevent import spawn, monkey
|
||||||
|
monkey.patch_all()
|
||||||
|
|
||||||
|
import pygame
|
||||||
|
from pygame import locals as pygamelocals
|
||||||
|
|
||||||
|
from gevent.server import DatagramServer
|
||||||
|
from gevent.queue import Queue
|
||||||
|
|
||||||
|
class PixelVloedServer(DatagramServer):
|
||||||
|
"""PixelVloed server class"""
|
||||||
|
|
||||||
|
def __init__(self, *args, **kwargs):
|
||||||
|
"""Set up some vars for this instance"""
|
||||||
|
self.queue = Queue()
|
||||||
|
pixelcanvas = Canvas(self.queue, kwargs['options'])
|
||||||
|
__request_processing_greenlet = spawn(pixelcanvas.CanvasUpdate)
|
||||||
|
del (kwargs['options'])
|
||||||
|
DatagramServer.__init__(self, *args, **kwargs)
|
||||||
|
|
||||||
|
def handle(self, data, _address):
|
||||||
|
"""Is called by the DataGramServer whenever an udp package is received"""
|
||||||
|
self.queue.put(data)
|
||||||
|
|
||||||
import optparse
|
import optparse
|
||||||
parser = optparse.OptionParser()
|
parser = optparse.OptionParser()
|
||||||
parser.add_option('-v', action="store_true", dest="debug", default=False)
|
parser.add_option('-v', action="store_true", dest="debug", default=False)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue