Get client stop function working
This commit is contained in:
parent
d843b3d619
commit
bd6ec4c41e
2 changed files with 16 additions and 2 deletions
|
|
@ -100,6 +100,8 @@ void NetworkClient::StartClient()
|
||||||
|
|
||||||
port.tcp_client(port_ip, port_str);
|
port.tcp_client(port_ip, port_str);
|
||||||
|
|
||||||
|
client_active = true;
|
||||||
|
|
||||||
//Start the connection thread
|
//Start the connection thread
|
||||||
ConnectionThread = new std::thread(&NetworkClient::ConnectionThreadFunction, this);
|
ConnectionThread = new std::thread(&NetworkClient::ConnectionThreadFunction, this);
|
||||||
|
|
||||||
|
|
@ -111,7 +113,18 @@ void NetworkClient::StartClient()
|
||||||
|
|
||||||
void NetworkClient::StopClient()
|
void NetworkClient::StopClient()
|
||||||
{
|
{
|
||||||
|
server_connected = false;
|
||||||
|
client_active = false;
|
||||||
|
|
||||||
|
shutdown(client_sock, SD_RECEIVE);
|
||||||
|
closesocket(client_sock);
|
||||||
|
ListenThread->join();
|
||||||
|
ConnectionThread->join();
|
||||||
|
|
||||||
|
/*-------------------------------------------------*\
|
||||||
|
| Client info has changed, call the callbacks |
|
||||||
|
\*-------------------------------------------------*/
|
||||||
|
ClientInfoChanged();
|
||||||
}
|
}
|
||||||
|
|
||||||
void NetworkClient::ConnectionThreadFunction()
|
void NetworkClient::ConnectionThreadFunction()
|
||||||
|
|
@ -119,7 +132,7 @@ void NetworkClient::ConnectionThreadFunction()
|
||||||
unsigned int requested_controllers;
|
unsigned int requested_controllers;
|
||||||
|
|
||||||
//This thread manages the connection to the server
|
//This thread manages the connection to the server
|
||||||
while(1)
|
while(client_active == true)
|
||||||
{
|
{
|
||||||
if(server_connected == false)
|
if(server_connected == false)
|
||||||
{
|
{
|
||||||
|
|
@ -243,7 +256,7 @@ void NetworkClient::ListenThreadFunction()
|
||||||
{
|
{
|
||||||
printf("Network client listener started\n");
|
printf("Network client listener started\n");
|
||||||
//This thread handles messages received from the server
|
//This thread handles messages received from the server
|
||||||
while(server_connected = true)
|
while(server_connected == true)
|
||||||
{
|
{
|
||||||
NetPacketHeader header;
|
NetPacketHeader header;
|
||||||
int bytes_read = 0;
|
int bytes_read = 0;
|
||||||
|
|
|
||||||
|
|
@ -70,6 +70,7 @@ private:
|
||||||
net_port port;
|
net_port port;
|
||||||
char port_ip[20];
|
char port_ip[20];
|
||||||
unsigned short port_num;
|
unsigned short port_num;
|
||||||
|
bool client_active;
|
||||||
bool server_connected;
|
bool server_connected;
|
||||||
bool server_initialized;
|
bool server_initialized;
|
||||||
unsigned int server_controller_count;
|
unsigned int server_controller_count;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue