From 9b8a0d465e839a61210e1dda1ee358dea473df73 Mon Sep 17 00:00:00 2001 From: Adam Honse Date: Wed, 6 May 2020 13:44:37 -0500 Subject: [PATCH] Functions to set IP and port and start client --- NetworkClient.cpp | 49 +++++++++++++++++++++++++++++++++++++++++++---- NetworkClient.h | 16 ++++++++++++++-- 2 files changed, 59 insertions(+), 6 deletions(-) diff --git a/NetworkClient.cpp b/NetworkClient.cpp index 9f274e63..b1787179 100644 --- a/NetworkClient.cpp +++ b/NetworkClient.cpp @@ -15,12 +15,48 @@ static void Sleep(unsigned int milliseconds) NetworkClient::NetworkClient(std::vector& control) : controllers(control) { - unsigned int requested_controllers; - - port.tcp_client("127.0.0.1", "1337"); - + strcpy(port_ip, "127.0.0.1"); + port_num = 1337; server_connected = false; server_controller_count = 0; +} + +unsigned short NetworkClient::GetPort() +{ + return port_num; +} + +bool NetworkClient::GetOnline() +{ + return server_connected; +} + +void NetworkClient::SetIP(const char *new_ip) +{ + if(server_connected == false) + { + strcpy(port_ip, new_ip); + } +} + +void NetworkClient::SetPort(unsigned short new_port) +{ + if(server_connected == false) + { + port_num = new_port; + } +} + +void NetworkClient::StartClient() +{ + unsigned int requested_controllers; + + //Start a TCP server and launch threads + char port_str[6]; + snprintf(port_str, 6, "%d", port_num); + + port.tcp_client(port_ip, port_str); + requested_controllers = 0; //Start the connection thread @@ -70,6 +106,11 @@ NetworkClient::NetworkClient(std::vector& control) : controller } } +void NetworkClient::StopClient() +{ + +} + void NetworkClient::ConnectionThreadFunction() { //This thread manages the connection to the server diff --git a/NetworkClient.h b/NetworkClient.h index fadc2f33..78162568 100644 --- a/NetworkClient.h +++ b/NetworkClient.h @@ -11,8 +11,18 @@ class NetworkClient public: NetworkClient(std::vector& control); - void ConnectionThreadFunction(); - void ListenThreadFunction(); + const char * GetIP(); + unsigned short GetPort(); + bool GetOnline(); + + void SetIP(const char *new_ip); + void SetPort(unsigned short new_port); + + void StartClient(); + void StopClient(); + + void ConnectionThreadFunction(); + void ListenThreadFunction(); void ProcessReply_ControllerCount(unsigned int data_size, char * data); void ProcessReply_ControllerData(unsigned int data_size, char * data, unsigned int dev_idx); @@ -36,6 +46,8 @@ protected: private: net_port port; + char port_ip[20]; + unsigned short port_num; bool server_connected; unsigned int server_controller_count;