Skip to content

Instantly share code, notes, and snippets.

@CallumJHays
Created August 14, 2016 05:36
Show Gist options
  • Save CallumJHays/46446ded4b1f80e3ed7bd364d39daff5 to your computer and use it in GitHub Desktop.
Save CallumJHays/46446ded4b1f80e3ed7bd364d39daff5 to your computer and use it in GitHub Desktop.
from socketIO_client import SocketIO, BaseNamespace
import logging
logging.getLogger('socketIO-client').setLevel(logging.DEBUG)
device_info = {
'name': "PYTHON TEST DEVICE",
'secret': "lmaolmao",
'width': 360,
'height': 240
}
class DeviceNamespace(BaseNamespace):
def on_connect(self):
socket.emit('new device', device_info)
def on_device_created(self, response):
print 'Device created! Response: '
print response
def on_command(self, commands):
print 'Recieved command: '
print commands
def on_disconnect(self):
print 'Server has disconnected'
def on_aaa_response(self):
print 'aaa'
print 'Setting up socket client'
socket = SocketIO('localhost', 80)
print 'Setting up device namespace'
device_namespace = socket.define(DeviceNamespace, '/deviceSocket')
print 'Attempting to connect to socket'
device_namespace.on('connect', device_namespace.on_socket_connect)
device_namespace.on('command', device_namespace.on_command)
device_namespace.on('disconnect', device_namespace.on_disconnect)
device_namespace.on('device_created', device_namespace.on_device_created)
socket.wait() # wait forever until
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment