-
Notifications
You must be signed in to change notification settings - Fork 0
/
servers.py
51 lines (35 loc) · 970 Bytes
/
servers.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
37
38
39
40
41
42
43
44
45
46
47
class Server:
__count = 0
def __init__(self):
Server.__count += 1
self.ip = Server.__count
self.buffer = []
self.rout = ''
def send_data(self, data):
self.rout.buffer += [data]
def get_data(self):
a = self.buffer.copy()
self.buffer = []
return a
def get_ip(self):
return self.ip
class Router:
def __init__(self):
self.buffer = []
self.servers = []
def link(self, server):
self.servers += [server]
server.rout = self
def unlink(self, server):
self.servers.remove(server)
server.router = ''
def send_data(self):
for i in self.buffer:
for j in self.servers:
if i.ip == j.ip:
j.buffer += [i]
self.buffer = []
class Data:
def __init__(self, data, ip):
self.data = data
self.ip = ip