-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathserver.py
More file actions
36 lines (24 loc) · 823 Bytes
/
server.py
File metadata and controls
36 lines (24 loc) · 823 Bytes
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
import socket
HOST = ""
PORT = 3042
sckt = socket.socket(socket.AF_INET, socket.SOCK_STREAM) #socket.AF_INET = IPV4 address, SOCK_STREAM = use TCP protocol
print("socket : ",sckt)
sckt.bind((HOST,PORT)) #Address Ip, Port
while True:
sckt.listen(5) # Listen incoming connexions
client,address = sckt.accept() # Return socket (client= new socket, address = (address IP, PORT))
print(f"{client} client")
print(f"{address} connected")
response = client.recv(1024) # Limit to 1024 characters
response = response.decode("utf8")
if response != "":
print("B")
messages = response.split("\n")
messages.pop()
print(messages)
for message in messages:
print(message)
response = ""
print("Close")
client.close()
sckt.close()