-
Notifications
You must be signed in to change notification settings - Fork 0
/
server.py
75 lines (58 loc) · 2.05 KB
/
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
import socket
import sys
from allfiles.ip import ip,port
while True:
try:
s=socket.socket(socket.AF_INET,socket.SOCK_STREAM)
s.bind((ip,port))
s.listen()
import mysql.connector
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="deens123"
)
mycursor = mydb.cursor()
mycursor.execute('use project')
print('ok')
while True:
clientsocket,address=s.accept()
print(f"connection from {address} has been established!")
#clientsocket.send('hi from server'.encode())
while True:
clientmsg = clientsocket.recv(10002400)
print(clientmsg)
import time
mycursor.execute(clientmsg.decode())
if 'select' not in clientmsg.decode():
mydb.commit()
clientsocket.close()
break
elif clientmsg.decode() == '':
clientsocket.close()
else:
out = mycursor.fetchall()
string = ''
if out != []:
for i in out:
string += str(i) + ";"
print(string)
clientsocket.send(string.encode())
else:
i = ('',)
string = str(i)+';'
print(string)
clientsocket.send(string.encode())
if not clientmsg:
print(f'Client disconnected: {address}')
clientsocket.close()
break
mydb = mysql.connector.connect(
host="localhost",
user="root",
password="deens123"
)
mycursor = mydb.cursor()
mycursor.execute('use project')
except Exception as e:
print('\n\nERROR :',e,'\n\n')