From 4e9f4d46f17c1fefca10c7e822cd537a6c49a9b9 Mon Sep 17 00:00:00 2001 From: mmcwilliams Date: Sat, 6 Apr 2024 11:26:16 -0400 Subject: [PATCH] Got working with macOS --- main.cpp | 11 +++++++---- send.py | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/main.cpp b/main.cpp index 31d04f6..ebeec15 100644 --- a/main.cpp +++ b/main.cpp @@ -21,6 +21,7 @@ using namespace std; using namespace std::chrono; const int DISPLAY_DURATION = 2000; +const int PORT = 8081; steady_clock::time_point startTime; bool shouldDisplayQuad = false; @@ -122,10 +123,12 @@ int main(int argc, char** argv) { struct sockaddr_in serverAddr; serverAddr.sin_family = AF_INET; serverAddr.sin_addr.s_addr = INADDR_ANY; - serverAddr.sin_port = htons(8080); + serverAddr.sin_port = htons(PORT); - if (bind(serverSocket, (struct sockaddr*)&serverAddr, sizeof(serverAddr)) < 0) { - cerr << "Error binding socket" << endl; + int bindResult = ::bind(serverSocket, reinterpret_cast(&serverAddr), sizeof(serverAddr)); + if (bindResult < 0) { + std::cerr << "Error binding socket" << std::endl; + close(serverSocket); return 1; } @@ -134,7 +137,7 @@ int main(int argc, char** argv) { return 1; } - cout << "TCP server listening on port 8080" << endl; + cout << "TCP server listening on port " << PORT << endl; thread serverThread(runTCPServer, serverSocket); diff --git a/send.py b/send.py index d607eef..d39d297 100644 --- a/send.py +++ b/send.py @@ -3,7 +3,7 @@ import json client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM) -server_address = ('localhost', 8080) +server_address = ('localhost', 8081) print(f'Connecting to {server_address}...') client_socket.connect(server_address)