Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions webapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ def boardcast(msg_type, messages):

ws = request.environ['wsgi.websocket']
ws_id = id(ws)
print 'New connect: %r --> %r' % (cid, ws_id)
print('New connect: %r --> %r' % (cid, ws_id))

ws_lst = WS_DICT.get(cid, [])
if len(ws_lst) == 0:
Expand Down Expand Up @@ -95,20 +95,20 @@ def close_client(e=None):
boardcast('offline', [message])
MEMBERS.pop(cid)

print u'[%r, %r]: {Closed}' % (cid, ws_id)
if e is not None: print type(e)
print(u'[%r, %r]: {Closed}' % (cid, ws_id))
if e is not None: print(type(e))
return ''

while True:
try:
body = ws.receive()
if body is None: return close_client()
except WebSocketError, e:
except WebSocketError as e:
return close_client(e)

now = datetime.now().strftime("%m-%d %H:%M:%S")
body = unicode(body, encoding='utf-8')
print u'[%r, %r]: %s' % (cid, ws_id, body)
body = body.encode("UTF-8")
print(u'[%r, %r]: %s'.encode("UTF-8") % (cid, ws_id, body))
message = {
'cid': cid,
'type': 'message',
Expand All @@ -124,5 +124,5 @@ def close_client(e=None):
import sys
port = int(sys.argv[1])
http_server = WSGIServer(('0.0.0.0', port), app, handler_class=WebSocketHandler)
print 'Server started at: 0.0.0.0:{0}'.format(port)
print('Server started at: 0.0.0.0:{0}'.format(port))
http_server.serve_forever()