Csocket-based LAN chat file transmission software C/S Mode

Source: Internet
Author: User

First of all, we do not recommend that you use csocket for your experience. The encapsulation class derived from casyncsocket is synchronous blocking Socket. That is to say, the programming process is a lot of trouble, but I stick to it ..... So annoying ....

........................................ ......... Split line ....................................... ........................................ ......

In fact, it is easy to understand the idea that S (server side) creates a socket, listen () whether the client is connected, and then the Socket connected by accept. C (client) creates a socket and connects to connect () s, so that the basic structure is formed. Then you can send and receive.

To transfer text and files, we recommend that you use two ports and use another thread to transfer files. This will avoid errors. After all, csocket is blocked synchronously, so it is annoying .... If a socket is used, it is prone to errors. Specifically, it is easy to receive error information.

Procedure:

1. The server obtains the IP address of the Local Machine and displays it in the IP control. Then, the user of S tells the user of C that my IPI is the IP address and you are connected to this IP address. (Of course, you must use other methods). Create a socket> listen ()-> Accept () based on the IP address and an unused port ();

2. c. Connect according to the IP address specified by S. Then both parties can send and receive text.

3. File Transfer Method

(1) S-> C: s click the button, and then pass the text to C, I want to send you a file, and then create the socket, accept () wait for C to respond. Click the "c" button to receive the file, send a text message to S, and connect to the socket established by S. (The IP address has been known before and the port is written to death.), saccept () to C, send the file. For details about how to send files, see the following section.

(2) c-> S: I don't think it is necessary to know the IP address of C, so I still need to establish socket in S. When C tells s that I want to send it, s establishes, accept, say, "I'm ready." Send it, Connect C to connect (), send the file, and s to receive it.

This verification method for sending files is still to be elaborated. I also wrote it for the first time ..... I am thinking about sending files via QQ.

4. When sending a file, I set the buffer and send it cyclically. This will transfer files of all sizes.

Csocket-based LAN chat file transmission software C/S Mode

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.