forked from ndleah/python-mini-project
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathserver.py
More file actions
23 lines (14 loc) · 689 Bytes
/
server.py
File metadata and controls
23 lines (14 loc) · 689 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import socket
HOST = 'localhost' # host where the server is located
PORT = 3000 # port the server is on
s = socket.socket() # new socket with name s
s.bind((HOST, PORT)) # bind host and port to socket
s.listen() # start the server to receive connections
print("Server runing in port ", PORT) # print port address
while True:
conn, addr = s.accept() # accept connections
res = conn.recv(1024) # buffer size to receive the data sent from the client
print('New conection', addr) # print the address of the current connection
print(res) # print data receive from client
conn.send(b' Hello from server!') # send data to client
conn.close() #close the conection