-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
34 lines (25 loc) · 733 Bytes
/
server.py
File metadata and controls
34 lines (25 loc) · 733 Bytes
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
29
30
31
32
33
34
# -*- coding: utf-8 -*-
"""
Created on Thu Sep 6 00:13:09 2018
@author: Jhon GIl Sepulveda
"""
from SimpleWebSocketServer import SimpleWebSocketServer, WebSocket
import sys
import json
port = 8095
clients = []
class SimpleEcho(WebSocket):
def handleMessage(self):
# echo message back to client
# self.sendMessage(self.data)
print(json.loads(self.data))
for client in clients:
client.sendMessage(self.data)
def handleConnected(self):
print(self.address, 'connected')
clients.append(self)
def handleClose(self):
print(self.address, 'closed')
clients.remove(self)
server = SimpleWebSocketServer('', port, SimpleEcho)
server.serveforever()