My logic is this:
When opening the dialog, call AfxBeginThread (& amp; (Optimizer: : server_thd), 0); Creating a thread,
SocketThread=AfxBeginThread (& amp; (Optimizer: : server_thd), 0);//thread begin
I use tinder network analysis, can see already to start listening to the corresponding port,
Server_thd is a class of the static function and use of the socket and listen_sock are static variables,
The main binding and monitoring were as follows:
: : bind (listen_sock, (struct sockaddr *) & amp; Local_addr, sizeof (SOCKADDR_IN))
The sock=accept (listen_sock, (struct sockaddr *) & amp; Client_addr, & amp; IaddrSize)
When closing the dialog box, I want to close my listening, I invoke the
Shutdown (sock, SD_BOTH);
Closesocket (sock);
Shutdown (listen_sock SD_BOTH);
Closesocket (listen_sock);
The TerminateThread (SocketThread - & gt; M_hThread, 0);
But viewing from the tinder, or in the listener port, until the whole software close to stop listening, how do I stop listening?
CodePudding user response:
1 closed before setting a breakpoint, trial run and see whether the want to logic order2 threads do not recommend forced interruption, easy resource leaks, it is recommended to use mark way waiting for events such as
3 after the Socket is closed, the system in order to ensure the operation is not used to this immediately behind the connection and there will be a waiting time, pay attention to the
CodePudding user response: