Updated the sdl version so it is just as usable as the pygame version.
This commit is contained in:
parent
6e27713ace
commit
9678939aa0
2 changed files with 24 additions and 22 deletions
44
sdlvloed.py
44
sdlvloed.py
|
|
@ -12,17 +12,14 @@ __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()
|
||||
if __name__ == '__main__':
|
||||
from gevent import spawn, monkey
|
||||
monkey.patch_all()
|
||||
|
||||
import sdl2.ext
|
||||
import struct
|
||||
import time
|
||||
import socket
|
||||
|
||||
from gevent.server import DatagramServer
|
||||
from gevent.queue import Queue
|
||||
|
||||
UDP_IP = "127.0.0.1"
|
||||
UDP_PORT = 5005
|
||||
DISCOVER_PORT = 5006
|
||||
|
|
@ -176,21 +173,6 @@ class Canvas(object):
|
|||
"""Clean up any sockets we created"""
|
||||
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):
|
||||
"""Sets up a client
|
||||
|
||||
|
|
@ -326,6 +308,26 @@ def RunServer(options):
|
|||
options=options).serve_forever()
|
||||
|
||||
if __name__ == '__main__':
|
||||
import sdl2.ext
|
||||
|
||||
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
|
||||
parser = optparse.OptionParser()
|
||||
parser.add_option('-v', action="store_true", dest="debug", default=False)
|
||||
|
|
|
|||
2
vloed.py
2
vloed.py
|
|
@ -9,7 +9,7 @@ __version__ = 0.3
|
|||
__author__ = "Jan Klopper <jan@underdark.nl>"
|
||||
|
||||
if __name__ == '__main__':
|
||||
# avoid nasty eception on python closing time
|
||||
# avoid nasty exception on python closing time
|
||||
from gevent import spawn, monkey
|
||||
monkey.patch_all()
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue