22 lines
584 B
Python
22 lines
584 B
Python
import socket
|
|
|
|
def start_server():
|
|
host = socket.gethostname()
|
|
port = 5000
|
|
|
|
server_socket = socket.socket()
|
|
server_socket.bind((host, port))
|
|
|
|
# configure how many client the server can listen simultaneously
|
|
server_socket.listen(1)
|
|
conn, address = server_socket.accept() # accept new connection
|
|
print("Connection from: " + str(address))
|
|
while True:
|
|
# receive data stream. it won't accept data packet greater than 1024 bytes
|
|
data = conn.recv(1024).decode()
|
|
print(str(data))
|
|
|
|
|
|
conn.close() # close the connection
|
|
|