A tcp and UPD chat and file transfer program

Source: Internet
Author: User

 


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;
  
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.