-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient.py
More file actions
142 lines (118 loc) · 2.74 KB
/
client.py
File metadata and controls
142 lines (118 loc) · 2.74 KB
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
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
from tkinter import *
from tkinter import filedialog as fd
from tkinter.simpledialog import askstring
import socket
import ssl
fpath = "None"
output = ""
ftypes = (("C Files","*.c"),("Python Files","*.py"))
#create socket and establish connection and SSL handshake
client = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
ipaddr = "localhost" #Replace with desired IP Address
client.connect((ipaddr, 9999))
certificate_data = client.recv(4096)
cert_file_path = "server.crt"
with open(cert_file_path, "wb") as cert_file:
cert_file.write(certificate_data)
client_ssl = ssl.wrap_socket(client,ca_certs="./server.crt")
#Choosing a file
def setfilepath():
global fpath
fp = fd.askopenfilename(
title="select the code file",
filetypes=ftypes
)
fpath = fp
ff = "Selected File: {}".format(fp)
l0["text"] = ff
#Sending the file and receiving code output
def sendfile(fpath):
global output
f_name = askstring(title='',prompt="Enter Received File with Extension ")
file_name = f_name +"<END_FILENAME>"
client_ssl.send((file_name).encode())
t = client_ssl.recv(1024)
print(t.decode())
with open(fpath, "rb") as file:
while True:
data = file.read(1024)
if not data:
break
client_ssl.sendall(data)
client_ssl.send(b"<END>")
r = client_ssl.recv(1024)
print(r.decode())
output = client_ssl.recv(4096).decode()
print("Output:")
print(output)
l1["text"]=output
#GUI
window = Tk()
window.geometry("680x632")
window.configure(bg = "#44444c")
canvas = Canvas(
window,
bg = "#44444c",
height = 832,
width = 1280,
bd = 0,
highlightthickness = 0,
relief = "ridge"
)
canvas.place(x = 0, y = 0)
canvas.create_text(
325.0, 183,
text="Output",
fill="#ffffff",
font= "PTSans-Bold 13"
)
#Title
canvas.create_text(
325.0, 50,
text="Remote Code Compiler",
fill="#ffffff",
font= "PTSans-Bold 30"
)
l0 = Label(
window, text="Selected File: {}".format(fpath),
background="#44444c",
fg="#FFFFFF",
font="RobotoSans 12"
)
l0.place(x=40,y=107)
l1 = Label(
window,
text=output,
background="#FFFFFF",
anchor="nw",
width=93,
height= 80,
justify='left',
pady=0,
padx=0,
)
l1.place(x=10,y=200)
b0 = Button(
window,
text= "Select File Path",
borderwidth = 0,
highlightthickness = 0,
command= setfilepath
)
b0.place(
x = 206, y = 140,
width = 100,
height = 30)
b1 = Button(
window,
text="Send",
borderwidth=0,
highlightthickness=0,
command= lambda:sendfile(fpath)
)
b1.place(
x = 356, y = 140,
width = 100,
height = 30)
window.mainloop()
client_ssl.close()