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...
-
I get many confused emails from people trying to get UniWeb to work in the Unity WebPlayer. It works, but you have to set things up correctl...
-
So, you've created a car prefab using WheelCollider components, and now you can apply a motorTorque to make the whole thing move along. ...
-
Often, when building a game, you need to test if objects are colliding. The objects could be spaceships, rocks, mouse pointers, laser beams....
-
I went to the pulse expo this evening, where one of the speakers mentioned that Ubisoft are in town (Perth, Western Australia), looking to...
-
I'm about to release a Tech Tree editor tool for Unity. To test usability and work out how improve the interface, I used it to buil...
-
I've been working on something new. I get a lot of projects where I have to add multiuser functionality. Finally I've made the jump ...
-
I decided to double check my assumptions about Stackless and the GIL on a multicore machine, using the same example provided by David Beazl...
-
In my spare time this week, instead of building spaceships, playing games or even drinking beer... I will make a game for the Apple App Stor...
-
In the 7 years I've been actively involved in web development, I have never seen any of my peers bother implementing proper controls to ...