-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
peer.py
39 lines (30 loc) · 839 Bytes
/
peer.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
import sys
from client import *
from server import *
import time
class p2p:
peers = ['127.0.0.1']
def main():
msg = "test message".encode('utf-8')
while True:
try:
print("-" * 21 + "connecting" + "-" * 21)
time.sleep(2)
for peer in p2p.peers:
try:
client = ClientConnection(peer)
except KeyboardInterrupt:
sys.exit(0)
except:
pass
# become the server
try:
server = ServerConnection(msg)
except KeyboardInterrupt:
sys.exit()
except:
pass
except KeyboardInterrupt as e:
sys.exit(0)
if __name__ == "__main__":
main()