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 ~