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