MiddleMan: A Pub/Sub and Request/Response server in Go.
This is my first Go project. It is a rewrite of an existing Python server, based on some previous work: https://entitycrisis.blogspot.de/2016/09/python3-asyncio-pubsub-plaything.html
All code available here: https://github.com/simonwittber/middleman
I can see Go becoming my preferred language for game servers.
Thursday, December 29, 2016
Friday, September 23, 2016
Python3 Asyncio PubSub Plaything
#!/usr/bin/env python
import io
import asyncio
import websockets
import logging
import collections
logger = logging.getLogger('websockets.server')
logger.setLevel(logging.ERROR)
logger.addHandler(logging.StreamHandler())
events = collections.defaultdict(lambda: set())
#-----------------------------------------------------------------------
async def handle_outgoing_queue(websocket):
while websocket.open:
msg = await websocket.outbox.get()
await websocket.send(msg)
#-----------------------------------------------------------------------
async def pubsub(websocket, path):
websocket.prefix = path.encode()
websocket.outbox = asyncio.Queue()
websocket.subscriptions = set()
sender_task = asyncio.ensure_future(handle_outgoing_queue(websocket))
while True:
msg = await websocket.recv()
if msg is None: break
if isinstance(msg, str): msg = msg.encode()
stream = io.BytesIO(msg)
await handle_message(websocket, stream)
sender_task.cancel()
for name in websocket.subscriptions:
try:
events[name].remove(websocket)
except KeyError:
pass
#-----------------------------------------------------------------------
async def handle_message(websocket, stream):
cmd = stream.readline().strip()
name = websocket.prefix + stream.readline().strip()
print(cmd, name);
if cmd == b"SUB":
events[name].add(websocket)
websocket.subscriptions.add(name)
elif cmd == b"UNS":
subscribers = events[name]
try:
websocket.subscriptions.remove(name)
except KeyError:
pass
try:
subscribers.remove(websocket)
except KeyError:
pass
elif cmd == b"PUB":
stream.seek(0)
msg = stream.read()
for subscriber in events[name]:
await subscriber.outbox.put(msg)
#-----------------------------------------------------------------------
start_server = websockets.serve(pubsub, '0.0.0.0', 8765)
asyncio.get_event_loop().run_until_complete(start_server)
asyncio.get_event_loop().run_forever()
Sunday, January 03, 2016
Notes on DragAndDrop in the Unity Editor
The documentation for the Unity DragAndDrop class is a little lacking, so here are the notes from my experiments into how the whole things works and integrates with OnGUI.
* If the current event in your OnGUI function is MouseDrag, first call:
then assign a value to DragAndDrop.objectReferences or DragAndDrop.paths and then call:
* If the current event is DragUpdated, you need to check if the drag operation can succeed or fail, then set:
to an appropriate value. Important:If the drag operation could be accepted at this point, call:
which will allow the DragPerform event to occur correctly if the mouse button is released.
* If the current event is DragPerform, the drag operation has succeeded and you can perform whatever logic is needed. No further DragAndDrop calls need to be made.
* If the current event is DragExited, you know that the drag operation has ended and you can perform any cleanup needed. Note: This event always occurs, even when DragPerform has completed.
* If the current event in your OnGUI function is MouseDrag, first call:
DragAndDrop.PrepareStartDrag ()
then assign a value to DragAndDrop.objectReferences or DragAndDrop.paths and then call:
DragAndDrop.StartDrag(string title)
* If the current event is DragUpdated, you need to check if the drag operation can succeed or fail, then set:
DragAndDrop.visualMode = DragAndDropVisualMode.*
to an appropriate value. Important:If the drag operation could be accepted at this point, call:
DragAndDrop.AcceptDrag()
which will allow the DragPerform event to occur correctly if the mouse button is released.
* If the current event is DragPerform, the drag operation has succeeded and you can perform whatever logic is needed. No further DragAndDrop calls need to be made.
* If the current event is DragExited, you know that the drag operation has ended and you can perform any cleanup needed. Note: This event always occurs, even when DragPerform has completed.
Subscribe to:
Posts (Atom)
Popular Posts
-
These are the robots I've been working on for the last 12 months. They each weigh about 11 tonnes and have a 17 meter reach. The control...
-
This hard-to-see screenshot is a Generic Node Graph Editing framework I'm building. I'm hoping it can be used for any kind of node...
-
So, you've created a car prefab using WheelCollider components, and now you can apply a motorTorque to make the whole thing move along. ...
-
MiddleMan: A Pub/Sub and Request/Response server in Go. This is my first Go project. It is a rewrite of an existing Python server, based o...
-
Why would I ask that question? Python 3 has been available for some time now, yet uptake is slow. There aren't a whole lot of packages i...
-
It is about 8 degrees C this morning. So cold, especially when last week we had high twenties. To help solve the problem, a friend suggeste...
-
After my last post, I decided to benchmark the scaling properties of Stackless, Kamaelia, Fibra using the same hackysack algorithm. Left axi...
-
I'm now using bzr instead of svn. I'm pushing my repositories to: http://exactlysimilar.org/bzr/ I'm also auto publishing docume...
-
Possibly slightly more correct lighting. The rim light is now only applied in the direction of the sun, rather than being purely based on vi...
-
I've just read a newspaper article (courtesy of Kranzky ) from WA Business News documenting the malfeasance, gross negligence and misc...