forked from taskcontrols/py-taskcontrol
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main_sockets_single_server.py
36 lines (31 loc) · 1.08 KB
/
main_sockets_single_server.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
29
30
31
32
33
34
35
36
import socket
# Socket's Listeners
from taskcontrol.lib import SocketsBase
Socket = SocketsBase()
# def server_handler(conn, addr, socket_server):
# print("SERVER", conn, addr)
# while True:
# data = conn.recv(1024).decode()
# if data:
# print("Data \n", data)
# if data == "close":
# conn.close()
# else:
# conn.send("close".encode())
# break
# conn.close()
# print("SERVER ", socket_server.get("host"), socket_server.get("port"))
# # print(socket_server.get("server").close())
def server_handler(conn, addr, socket_object):
data = conn.recv(1024)
print(data)
if not data:
conn.send("Test")
conn.sendall(data)
config = {"name": "test", "protocol": socket.AF_INET, "streammode": socket.SOCK_STREAM,
"host": "127.0.0.1", "port": 9001, "numbers": 1, "handler": None, "close_server": True}
# METHOD ONE:
s = Socket.socket_create(config)
if s:
print("Server started")
sr = Socket.socket_listen(config.get("name"))