Added server python script

This commit is contained in:
WickedJack99
2023-11-26 14:38:58 +01:00
parent 1b2987cf7d
commit 52b0fbcfee

36
agent.py Normal file
View File

@@ -0,0 +1,36 @@
# echo-server.py
import socket
import ssl
def start_server():
host = '127.0.0.1'
port = 5000
# Create a socket and bind it to the specified address and port
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.bind((host, port))
server_socket.listen(1)
print(f"Server listening on {host}:{port}")
while True:
# Accept incoming connections
client_socket, client_address = server_socket.accept()
print(f"Accepted connection from {client_address}")
# Wrap the client socket with SSL
ssl_socket = ssl.wrap_socket(client_socket, server_side=True, certfile='server.crt', keyfile='server.key', ssl_version=ssl.PROTOCOL_TLS)
# Read data from the client
data = ssl_socket.recv(1024).decode('utf-8')
print(f"Received from client: {data}")
# Send a response to the client
ssl_socket.send("Hello, Client!".encode('utf-8'))
# Close the connection
ssl_socket.close()
if __name__ == "__main__":
start_server()