-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
31 lines (22 loc) · 711 Bytes
/
Copy pathserver.py
File metadata and controls
31 lines (22 loc) · 711 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
#we add socket library
import socket
#Assign Ip and Port
host = "127.0.0.1"
port = 10001
#Create object IPV4 and TCP
server_socket = socket.socket(socket.AF_INET,socket.SOCK_STREAM)
#Server bind to client and listen mode
server_socket.bind((host, port))
server_socket.listen()
#server_socket just wait at the door but conn receive message and addr show ip
conn, addr = server_socket.accept()
print("Connected from", str(addr))
#we create infinite loop
while True:
#receive message decoded and print
data = conn.recv(1024).decode()
print(data)
#Server send message to inform and Message is encoded
Response_data = "Message receive"
conn.send(Response_data.encode())
conn.close()