Home > Software engineering >  VS2013MFC based on TCP/IP communications of the realization of the function of the heart
VS2013MFC based on TCP/IP communications of the realization of the function of the heart

Time:11-17

I wrote a with VS2013MFC based on TCP/IP server and client, using a computer to control multiple computers to open the PPT, demo PPT on multiple projectors, perfect! But there is a regret, is not to achieve the heart function, I would like to use WSAIoctl to realize the heartbeat, procedure is as follows: compile, run all normal, but whether to separate the application on the server, alone on the client, or the client to the server, I deliberately withdrew from the server or client, such as more than 10 minutes, also does not have occurrence heartbeat, give advice or comments please!

//the realization of the heartbeat packets - open KeepAlive
/* BOOL bKeepAlive=TRUE;
Int nRet=: : setsockopt (sockClient, SOL_SOCKET, SO_KEEPALIVE, (char *) & amp; BKeepAlive, sizeof (bKeepAlive));
If (nRet!=0)
{
AfxMessageBox (_T (" error "));
return 0;
}
*///change the socket keep alive heartbeat package for 10 s, and send 3 times -- -- -- -- --
Settings KeepAlive parametersTcp_keepalive inKeepAlive={0};//input parameter
Tcp_keepalive outKeepAlive={0};//output parameter
Unsigned long ulBytesReturn=0;
InKeepAlive. Onoff=true;
InKeepAlive. Keepaliveinterval=400;//the time interval between two KeepAlive probe
InKeepAlive. Keepalivetime=100;//before the first KeepAlive exploration TCP free time
Int nRet=WSAIoctl (sockClient SIO_KEEPALIVE_VALS, & amp; InKeepAlive, sizeof (inKeepAlive),
& OutKeepAlive, sizeof (outKeepAlive), & amp; UlBytesReturn, NULL, NULL);
If (SOCKET_ERROR==nRet)
{
AfxMessageBox (_T (" error "));
return false;
}

CodePudding user response:

Choose FD_CLOSE WSAEventSelect, monitor the closing event

CodePudding user response:

You can create a connection to maintain heartbeat mechanism alone ~

CodePudding user response:

reference 1st floor zgl7903 response:
select FD_CLOSE WSAEventSelect, monitor the close event
hello, thank you for your reply!
The WSAEventSelect function where is the use? The sample code?

CodePudding user response:

"Use a computer to control multiple computers to open the PPT, on multiple projectors demo PPT"
I'm dizzy, I saw it was hooked curiosity you this application scenario
What is this application? Sounds very strange, ha ha

CodePudding user response:

Under the function of the heartbeat packets, you why not their implement a heartbeat function of application layer based on TCP, rely on TCP KEEPAVLIVE should be wide of the mark, then again, you are offline pull line, withdrew, TCP RST/FIN has been triggered, where what keepalive packet, keepalive is defined as last 2 hours do not send any package to give you a the underlying protocol of heartbeat packets

CodePudding user response:

Any time don't rely on the underlying protocol stacks of heartbeat packets to help your business level application, KEEPAVLIVE just the inside of the TCP stack to maintain his status of a single TCP connection, when the socket is closed or intermediate network is broken cause side closed this KEEPAVLIVE failure, and the protocol stack to maintain this timer cycle is too long, upper judgment basic does not have any meaning for you, it is best to implement a simple closed his contract, good debugging, time interval can be set for himself

CodePudding user response:

reference 4 floor teleinfor response:
"with a computer to control multiple computers to open the PPT, on multiple projectors demo PPT"
I'm dizzy, I saw it was hooked curiosity you this application scenario
What is this application? Sounds very strange appearance, ha ha


A low-cost immersion projection results show,

CodePudding user response:


KEEPAVLIVE my client and server are set, automatic heart, not because of long time to read and write leads to disconnect,
  • Related