-
Notifications
You must be signed in to change notification settings - Fork 3
/
server.py
35 lines (29 loc) · 900 Bytes
/
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
import socket
import time
def Main():
host = "localhost"
port = 1234
my_Socket = socket.socket()
my_Socket.bind((host, port))
my_Socket.listen(1)
conn, addr = my_Socket.accept()
print("Connection from: " + str(addr))
while True:
while True: # this line, if the client closed the connection, it waits for new connections.
try:
data = str(conn.recv(1024).decode())
print("Client: " + data)
break
except ConnectionResetError:
time.sleep(1)
conn, addr = my_Socket.accept()
print("Connection from: " + str(addr))
if data == "q":
break
else:
message = input(" -> ")
print("Waiting Client...")
conn.send(message.encode())
conn.close()
if __name__ == '__main__':
Main()