From e2d2c41ad4e7d915759e7b24f5b93db906e731c0 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Thu, 26 Sep 2024 13:20:46 +0200 Subject: [PATCH] websocket shenanigans worky --- src/C++/Socket/main.cpp | 3 +-- src/Python/socket/socketServer.py | 9 +++++---- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/C++/Socket/main.cpp b/src/C++/Socket/main.cpp index 2ccb171..1449e3a 100644 --- a/src/C++/Socket/main.cpp +++ b/src/C++/Socket/main.cpp @@ -6,7 +6,7 @@ using boost::asio::ip::tcp; int main() { try { - // Object creation + // Create an io_context object boost::asio::io_context io_context; // Resolve the server address and port @@ -32,7 +32,6 @@ int main() { // Send a message to the server std::string message; std::cout << "Enter message: "; - //read directly from the console and feed with cin to the message variable std::getline(std::cin, message); message += "\n"; // Add newline to mark the end of the message boost::asio::write(socket, boost::asio::buffer(message)); diff --git a/src/Python/socket/socketServer.py b/src/Python/socket/socketServer.py index 252994e..1bff9ef 100644 --- a/src/Python/socket/socketServer.py +++ b/src/Python/socket/socketServer.py @@ -1,19 +1,20 @@ import socket -HOST = "127.0.0.1" # Standard loopback interface address (localhost) +HOST = "127.0.0.1" # Listen on all available interfaces PORT = 4024 # Port to listen on (non-privileged ports are > 1023) with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s: s.bind((HOST, PORT)) s.listen() + print(f"Server listening on {HOST}:{PORT}") conn, addr = s.accept() with conn: print(f"Connected by {addr}") - conn.sendall(b"hallo") + conn.sendall(b"hallo\n") while True: data = conn.recv(2048) if data: - print("received", repr(data)) - conn.sendall(b"message received") + print("Received:", repr(data)) + conn.sendall(b"message received\n") if not data: break \ No newline at end of file