mirror of
https://gitlab.fdmci.hva.nl/technische-informatica-sm3/ti-projectten/rooziinuubii79.git
synced 2025-08-03 20:04:58 +00:00
websocket shenanigans worky
This commit is contained in:
@@ -6,7 +6,7 @@ using boost::asio::ip::tcp;
|
|||||||
|
|
||||||
int main() {
|
int main() {
|
||||||
try {
|
try {
|
||||||
// Object creation
|
// Create an io_context object
|
||||||
boost::asio::io_context io_context;
|
boost::asio::io_context io_context;
|
||||||
|
|
||||||
// Resolve the server address and port
|
// Resolve the server address and port
|
||||||
@@ -32,7 +32,6 @@ int main() {
|
|||||||
// Send a message to the server
|
// Send a message to the server
|
||||||
std::string message;
|
std::string message;
|
||||||
std::cout << "Enter message: ";
|
std::cout << "Enter message: ";
|
||||||
//read directly from the console and feed with cin to the message variable
|
|
||||||
std::getline(std::cin, message);
|
std::getline(std::cin, message);
|
||||||
message += "\n"; // Add newline to mark the end of the message
|
message += "\n"; // Add newline to mark the end of the message
|
||||||
boost::asio::write(socket, boost::asio::buffer(message));
|
boost::asio::write(socket, boost::asio::buffer(message));
|
||||||
|
@@ -1,19 +1,20 @@
|
|||||||
import socket
|
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)
|
PORT = 4024 # Port to listen on (non-privileged ports are > 1023)
|
||||||
|
|
||||||
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
with socket.socket(socket.AF_INET, socket.SOCK_STREAM) as s:
|
||||||
s.bind((HOST, PORT))
|
s.bind((HOST, PORT))
|
||||||
s.listen()
|
s.listen()
|
||||||
|
print(f"Server listening on {HOST}:{PORT}")
|
||||||
conn, addr = s.accept()
|
conn, addr = s.accept()
|
||||||
with conn:
|
with conn:
|
||||||
print(f"Connected by {addr}")
|
print(f"Connected by {addr}")
|
||||||
conn.sendall(b"hallo")
|
conn.sendall(b"hallo\n")
|
||||||
while True:
|
while True:
|
||||||
data = conn.recv(2048)
|
data = conn.recv(2048)
|
||||||
if data:
|
if data:
|
||||||
print("received", repr(data))
|
print("Received:", repr(data))
|
||||||
conn.sendall(b"message received")
|
conn.sendall(b"message received\n")
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
Reference in New Issue
Block a user