-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsocket_server.py
105 lines (74 loc) · 1.99 KB
/
socket_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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
# RSA Algorithm
# Message Receiver
from RSA_Decrypter import *
import os
from socket import *
s = socket()
# host = gethostname()
host = ""#"127.0.0.1"
port = 13000 #ports after 6000 are free
s.bind((host,port))
s.listen(10)
file = open('keys.json','rb')
print("Waiting for message")
while True:
c, addr = s.accept()
# print("Client connected",addr)
#print ("Got Connection from" ,addr)
l = c.recv(1024)
while (l):
file.write(l)
l = c.recv(1024)
file.close()
# content=c.recv(1024).decode()
print("Decrypting")
RSA_decrypt("keys.json")
# if data == "exit":
# break
s.close()
os.exit(0)
################################## ROUGH ##################################
# UDPSock = socket(AF_INET, SOCK_DGRAM)
# UDPSock.bind(addr)
# f = open('keys.json','rb')
# print("Waiting to receive messages...")
# while True:
# (c, addr) = UDPSock.accept()#recvfrom(buf)
# # print("Received message: " + data.decode())
# l = c.recv(1024)
# while (l):
# f.write(l)
# l = c.recv(1024)
# f.close()
# print("Decrypting")
# RSA_Decrypter()
# if data == "exit":
# break
# UDPSock.close()
# os._exit(0)
# s = socket()
# #host = gethostname()
# host=""
# port=13000 #ports after 6000 are free
# s.bind((host,port))
# s.listen(10)
# file = open('keys.json','wb')
# # # f = open('keys.json','wb')
# # # print("Waiting to receive messages...")
# while True:
# c, addr = s.accept()
# print("Client connected",addr)
# #print ("Got Connection from" ,addr)
# l = c.recv(1024)
# while (l):
# file.write(l)
# l = c.recv(1024)
# # with open('keys_server.json', 'w+') as fp :
# # json.dumps(file, fp)
# # f.close()
# print("Decrypting")
# RSA_decrypt("keys.json")
# # if data == "exit":
# # break
# s.close()
# os.exit(0)