Skip to content

Commit

Permalink
Merge branch 'master' of github.com:psubocz/garden-dWARves
Browse files Browse the repository at this point in the history
  • Loading branch information
lqc committed Apr 14, 2012
2 parents a5ebf63 + f74738f commit 7cf8bc3
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 4 deletions.
Binary file added client/statics/images/startScreen.png
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
39 changes: 37 additions & 2 deletions server/actor.py
@@ -1,5 +1,6 @@
from socketio.namespace import BaseNamespace from socketio.namespace import BaseNamespace

from gevent.queue import Queue
import gevent
UNCONNECTED = 0 UNCONNECTED = 0
CONNECTED = 1 CONNECTED = 1
SEARCHING = 2 SEARCHING = 2
Expand All @@ -10,7 +11,41 @@ class ActorProxy(BaseNamespace):


def initialize(self): def initialize(self):
self._state = UNCONNECTED self._state = UNCONNECTED

self.incoming_queue = Queue(0)

# spawn incoming queue greenlet
self.spawn(self._incoming)
self._actor = Actor()
self._actor.bind_proxy(self)
gevent.spawn(self._actor.run)

def _incoming(self):
for event,args in self.incoming_queue:
try:
self.emit(event, *args)
except Exception, e:
print e

def process_event(self, packet):
gevent.spawn(self._actor.inbox.put, (packet['name'], packet['args']))

class Actor(object):

def __init__(self):
self._proxy = None
self.inbox = Queue(0)

def bind_proxy(self, proxy):
self._proxy = proxy

def run(self):
for event,args in self.inbox:
fun = getattr(self, 'on_'+event)
fun(*args)

def emit(self, event, *args):
gevent.spawn(self._proxy.incoming_queue.put, (event, args))

def on_connect(self, udata): def on_connect(self, udata):
self._udata = udata self._udata = udata
self._change_state(CONNECTED) self._change_state(CONNECTED)
Expand Down
5 changes: 3 additions & 2 deletions server/server.py
Expand Up @@ -22,8 +22,9 @@ def handle_src(path):


@route('/') @route('/')
def handle_index(): def handle_index():
return static_file('index.html', root='../client/statics') #return static_file('index.html', root='../client/statics')

return static_file('index.html', root='clitest/')

print "Starting socket.io server at %s:%d" % (config.SOCKETIO_IFACE, config.SOCKETIO_PORT) print "Starting socket.io server at %s:%d" % (config.SOCKETIO_IFACE, config.SOCKETIO_PORT)
SocketIOServer((config.SOCKETIO_IFACE, config.SOCKETIO_PORT), bottle.default_app(), namespace="socket.io").serve_forever() SocketIOServer((config.SOCKETIO_IFACE, config.SOCKETIO_PORT), bottle.default_app(), namespace="socket.io").serve_forever()


0 comments on commit 7cf8bc3

Please sign in to comment.