UDP-based file transfer gadget in LAN

Source: Internet
Author: User

First, the goal

A small tool for designing a file transfer based on UDP to understand the characteristics of the UDP protocol.

Content:

Basic requirements:

Enter the IP address of the other party, if it exists, you can send files to each other.

Extension requirements:

(1) The tool has a friendly user interface;

(2) The two hosts using the tool in the LAN can communicate with each other in text;

(3) Automatically according to a certain frequency scan LAN other open the tool host, and in the interface with a list display;

(4) Transfer files and text content, directly select the interface has been shown on the surviving host, do not need to enter the IP address manually.

Ii. Design and implementation
Environment:

Ubuntu14.04+gcc4.8+eclipse

Key Links:

1. User point-to-point communication, communication content for text messages and file transfer, the use of IP servers to record online users, users on-line offline automatically notify the configured IP server, while users can always want IP server request online all users.

2. Use poll to implement IO multiplexing, listening to the reading and writing of standard input file descriptors and communication sockets.

3. Make commands such as "msgs", "File", "list", "Q" and so on.

How to use:

Msgs an IP port message that represents a text message to the specified IP port.

File IP Port filepath, which represents the transfer of text filepath to the port of the specified IP.

List, which represents the request to the configured IP server for online users.

Q, represents the launch client.

4. Detailed Customer communication process

During the operation of the whole client, there are three kinds of messages, namely the online User IP display, text message sending and displaying, and the sending and storing of the files. Therefore, we use a single byte tag on each message packet to differentiate between IP list messages, text messages, and file transfers.

At the same time, in order to ensure the integrity of the transmission, we in the file transfer, but also in the message header added a file header structure, which recorded the file name, size and sent size.

Third, the effect of the program

1. Start the IP server

2. Start two sample clients, between two clients, and between the client and server, can communicate through the corresponding MSGS,FILE,LIST,Q and other commands.

The experiment successfully transmits the text message, the picture and the video and so on various kinds of files, the large file (two size 5G movie) transmission speed is probably 4m/s, because the LAN network simple, does not lose the packet, the packet order is correct, therefore guaranteed the data integrity and the correctness.

The experiment found that when transmitting large files, if the sending data is too fast, it will cause the loss of the packet, so we send the interval 5 milliseconds.

Here is Client 1:

Client 2:

IP server:

File transfer:

Iv. source code of the procedure

: Https://github.com/panzhengguang/Unix_Net_Programming/tree/master/UdpFileTrans

UDP-based file transfer gadget in LAN

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.