-
Notifications
You must be signed in to change notification settings - Fork 0
/
client.py
28 lines (22 loc) · 845 Bytes
/
client.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import ws4py.client.threadedclient
from config import *
import cPickle
class WebsocketClient(ws4py.client.threadedclient.WebSocketClient):
def __init__(self, host=None):
if host is None:
host = "localhost"
address = "ws://%s:%s%s" % (host, WEBSOCKET_PORT, WEBSOCKET_APPLICATION)
print address
ws4py.client.threadedclient.WebSocketClient.__init__(self, address)
def opened(self):
print "connected to server"
def closed(self, code, reason=None):
print "Closed down", code, reason
def received_message(self, message):
event = cPickle.loads(str(message))
# print "got from server: %s" % event
self.received_event(event)
def received_event(self, event):
pass
def send_event(self, event):
self.send(cPickle.dumps(event))