|
What I do is asynchronous socket server side. The approximate code is as follows:
private void form_load()
{
Get server IP and listening port
Start the listening thread
}
private void listening()
{
while(true)
{
lisdone.rest();
mysocket.beginaccept (call the asynchronous listener callback function);
lisdone.waitone();
}
}
private void acceptcallback()//Asynchronous callback function
{
Start the receiving thread for the current link client (as long as there is a client link, start a thread for this client)
}
private void receivedata()
{
while(true)
{
try
{
receivedone.rest();
mysocket.beginreceive (call the receive callback function)
receivedoen.waitone();
}
catch
{
mysocket.shutdown(shutdown.receive);
mysocket.close();
return;
}
}
}
private void receivecallback()
{
receivedone.set();
Receive data
}
The above is roughly the process of SOCKET server-side linking from client to receiving client data. Now I have a problem. My current method is as long as there are customer links. Just create a thread for receiving this client for this client in the listening callback function. This program can also be received normally. But when the customer quit halfway, the CPU usage of my program soared to 100. What is going on? ? When the link client is prominent, how should I release the client's link object? How to release the thread created after this client link comes up? ? Thank you, I look forward to replying. . . |
|