Merge pull request #1 from hornetfighter515/feature/py-hub
Preliminary python hub code
This commit is contained in:
commit
845b6f2a42
22
src/hub/hub.py
Normal file
22
src/hub/hub.py
Normal file
|
@ -0,0 +1,22 @@
|
|||
"""
|
||||
Creates hub for distributed IoT
|
||||
|
||||
@author hornetfighter515
|
||||
@author Lachezar Todorov
|
||||
"""
|
||||
|
||||
from websocket_server import WebsocketServer
|
||||
|
||||
def new_client(client, server):
|
||||
print("Client has joined")
|
||||
|
||||
def message_received(client, server, message):
|
||||
print(message)
|
||||
|
||||
int_server = WebsocketServer(host='127.0.0.1', port=6872)
|
||||
|
||||
|
||||
ext_server = WebsocketServer(host='127.0.0.1', port=6873)
|
||||
ext_server.set_fn_message_received(message_received)
|
||||
ext_server.set_fn_new_client(new_client)
|
||||
ext_server.run_forever()
|
37
src/py-cli/make_sockets.py
Executable file
37
src/py-cli/make_sockets.py
Executable file
|
@ -0,0 +1,37 @@
|
|||
"""
|
||||
A file that makes a bunch of sockets
|
||||
|
||||
@author Lachezar Todorov
|
||||
"""
|
||||
|
||||
class WebSockestServerExternal():
|
||||
|
||||
def __init__(self):
|
||||
self.wsl = [10]
|
||||
self.count = 0
|
||||
|
||||
|
||||
#start session
|
||||
def login(self, name):
|
||||
self.wsl[self.count] = name
|
||||
self.count += 1
|
||||
self.printing()
|
||||
|
||||
#exit session
|
||||
def logout(self, name):
|
||||
for name in self.wsl:
|
||||
if name == name:
|
||||
index = self.wsl.index(name)
|
||||
self.wsl[index] = ""
|
||||
self.printing()
|
||||
|
||||
#print out the list
|
||||
def printing(self):
|
||||
for name in self.wsl:
|
||||
print(name)
|
||||
|
||||
WebSockestServerExternal()
|
||||
|
||||
#alice.login()
|
||||
#alice.logout()
|
||||
|
Loading…
Reference in New Issue
Block a user