Abstract:
This article uses examples to show how to chat, send files to each other, and capture the screen of the recipient to save as a file in the LAN. The program also includes obtaining the IP address and computer name of the Local Machine and the other party. Provides functions such as The ListBox control.
The running interface is as follows:
1. Start and terminate the listening thread (only about TCP)
This program can be switched instantly, so it is necessary to end the thread that is still in the accept state.
// TCP listening thread
UINT _ ListenTcpThread (LPVOID lparam)
{
CMyQQDlg * pDlg = (CMyQQDlg *) lparam;
CSocket sockSrvr;
PDlg-> m_Potr = PORT + pDlg-> m_server; // Save the current PORT used for disabling
Int createSucceed = sockSrvr. Create (pDlg-> m_Potr );
Int listenSucceed = sockSrvr. Listen ();// Start listening
CSocket recSo;
SOCKADDR_IN client;
Int iAddrSize = sizeof (client );
Int acceptSucceed = sockSrvr. Accept (recSo, (SOCKADDR *) & client, & iAddrSize );// Accept the connection and obtain the IP address of the other party
SockSrvr. Close ();
Char flag [FLAG] = {0 };// Acceptance mark, used to determine whether information and files are accepted
If (recSo. Receive (flag, FLAG )! = 2)
{
Return-1;
}
PDlg-> m_type = flag [0];
If (pDlg-> m_type = D) return 0; // terminate this thread
PThreadLisen =: AfxBeginThread (_ ListenTcpThread, pDlg );
PDlg-> ReceiveFileMsg (recSo, client );
Return 0;
}
Close
If (m_nSockType = SOCK_TCP)
{
DWORDDwStatus;