CN107172181B - File transmission method based on double threads - Google Patents
File transmission method based on double threads Download PDFInfo
- Publication number
- CN107172181B CN107172181B CN201710421095.8A CN201710421095A CN107172181B CN 107172181 B CN107172181 B CN 107172181B CN 201710421095 A CN201710421095 A CN 201710421095A CN 107172181 B CN107172181 B CN 107172181B
- Authority
- CN
- China
- Prior art keywords
- data packet
- sub
- thread
- data
- sent
- Prior art date
- Legal status (The legal status is an assumption and is not a legal conclusion. Google has not performed a legal analysis and makes no representation as to the accuracy of the status listed.)
- Active
Links
Images
Classifications
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/06—Protocols specially adapted for file transfer, e.g. file transfer protocol [FTP]
-
- G—PHYSICS
- G06—COMPUTING; CALCULATING OR COUNTING
- G06F—ELECTRIC DIGITAL DATA PROCESSING
- G06F9/00—Arrangements for program control, e.g. control units
- G06F9/06—Arrangements for program control, e.g. control units using stored programs, i.e. using an internal store of processing equipment to receive or retain programs
- G06F9/46—Multiprogramming arrangements
- G06F9/54—Interprogram communication
- G06F9/546—Message passing systems or structures, e.g. queues
-
- H—ELECTRICITY
- H04—ELECTRIC COMMUNICATION TECHNIQUE
- H04L—TRANSMISSION OF DIGITAL INFORMATION, e.g. TELEGRAPHIC COMMUNICATION
- H04L67/00—Network arrangements or protocols for supporting network services or applications
- H04L67/01—Protocols
- H04L67/10—Protocols in which an application is distributed across nodes in the network
- H04L67/104—Peer-to-peer [P2P] networks
- H04L67/1074—Peer-to-peer [P2P] networks for supporting data block transmission mechanisms
- H04L67/1078—Resource delivery mechanisms
- H04L67/108—Resource delivery mechanisms characterised by resources being split in blocks or fragments
Landscapes
- Engineering & Computer Science (AREA)
- Computer Networks & Wireless Communication (AREA)
- Signal Processing (AREA)
- Software Systems (AREA)
- Theoretical Computer Science (AREA)
- Physics & Mathematics (AREA)
- General Engineering & Computer Science (AREA)
- General Physics & Mathematics (AREA)
- Communication Control (AREA)
Abstract
The invention provides a file transmission method based on double threads, which comprises the following steps: the data packet sending thread divides the file into n sub-data packets according to the sequence from 1 to n and sends the number n of the sub-data packets to the data packet receiving thread through a serial port; a data packet receiving thread establishes a queue arranged from 1 to n according to the number n of the sub data packets; the data packet sending thread sends the data packets to the serial port according to the sequence from 1 to n at a fixed frequency, and simultaneously detects whether the number of the data packets needing to be retransmitted or a file transmission completion notification sent by the data packet receiving thread is received; if a file transmission completion notification is received, stopping a data packet sending thread; if the sub-data packet number needing to be retransmitted is received, the sub-data packet with the corresponding number is preferentially sent; if not, the next sub-data packet is continuously sent in sequence.
Description
Technical Field
The invention relates to a file transmission method, in particular to a file transmission method based on double threads.
Background
Terminal devices of the automatic ticket selling and checking system of urban rail transit, such as an automatic ticket vending machine, a semi-automatic ticket vending machine, a gate machine, an automatic ticket taking machine, an inquiry machine and the like, acquire various parameter files and program files from a station center server and then transmit the files to ticket card processing equipment. Usually, a serial communication mode is often adopted when a terminal device of an automatic ticket selling and checking system for urban rail transit transmits a file to a ticket card processing device, as shown in fig. 1, a transmitting end can continue to transmit a next data packet only when receiving feedback from a receiving end, and when the file is large, because the serial communication has more waiting links and a long single-thread execution cycle, the transmission time is also long, and errors are easy to occur.
In order to solve the above problems, people are always seeking an ideal technical solution.
Disclosure of Invention
The invention aims to overcome the defects of the prior art, and provides a file transmission method based on double threads, which has the advantages of simple method and less time consumption.
In order to achieve the purpose, the invention adopts the technical scheme that: a file transmission method based on double threads comprises the following steps:
preparation phase
A data packet sending thread, which divides the file into n data blocks according to a fixed length, each data block is packaged into a sub data packet, the sub data packets are numbered from 1 to n according to the sequence in the file, and the number n of the sub data packets is sent to a data packet receiving thread through a serial port;
the data packet receiving thread receives the number n of the sub data packets sent by the data packet sending thread from the serial port and establishes a queue which is arranged from the number 1 to n of the sub data packets;
transmission phase
The data packet sending thread sends the data packets to the serial port at a fixed frequency according to a sending sequence from 1 to n, and simultaneously detects whether the number of the data packets needing to be retransmitted or a file transmission completion notification sent by the data packet receiving thread is received; if a file transmission completion notification is received, stopping a data packet sending thread; if the sub-data packet number needing to be retransmitted is received, the sub-data packet with the corresponding number is preferentially sent; if not, continuing to send the next sub-data packet in sequence;
after the data packet receiving thread receives the current data packet sent by the serial port, deleting the number of the corresponding data packet in the queue according to the number x of the current data packet, judging whether the queue is empty, if so, sending a file transmission completion notification to the data packet sending thread, and stopping the data packet receiving thread; if not, judging whether a sub-data packet number smaller than x exists in the queue, if so, returning the sub-data packet number to a data packet sending thread, and if not, waiting for receiving the next sub-data packet.
Based on the above, if the preset time is exceeded, the data packet receiving thread does not receive the sub data packet sent by the serial port, and the queue is not empty, the data packet sending thread and the data packet receiving thread are stopped.
Based on the above, after the data packet sending thread or the data packet receiving thread is stopped, the memory data of the corresponding thread is cleared.
Compared with the prior art, the method has outstanding substantive characteristics and remarkable progress, and particularly, the method adopts double threads to transmit files, simultaneously the data packet sending thread sends sub data packets to the serial port at fixed intervals, whether the data packet receiving thread receives the data packets or not is not considered, the data packet receiving thread also feeds back the data packet number to be retransmitted to the data packet receiving thread in real time according to the received data packet number, the sending process and the receiving process are carried out simultaneously, the problems of low serial port communication speed and high error probability are effectively solved, and the method has the advantages of simplicity and short time.
Drawings
FIG. 1 is a conventional serial port communication process;
fig. 2 is a schematic flow chart of a file transmission method according to the present invention.
Detailed Description
The technical solution of the present invention is further described in detail by the following embodiments.
As shown in fig. 2, a file transmission method based on dual threads includes the following steps:
preparation phase
A data packet sending thread, which divides the file into n data blocks according to a fixed length, each data block is packaged into a sub data packet, the sub data packets are numbered from 1 to n according to the sequence in the file, and the number n of the sub data packets is sent to a data packet receiving thread through a serial port;
the data packet receiving thread receives the number n of the sub data packets sent by the data packet sending thread from the serial port and establishes a queue which is sequentially arranged from the number 1 to n of the sub data packets;
transmission phase
The data packet sending thread sends the data packets to the serial port at a fixed frequency according to a sending sequence from 1 to n, and simultaneously detects whether the number of the data packets needing to be retransmitted or a file transmission completion notification sent by the data packet receiving thread is received; if a notice that the file transmission is finished is received, stopping a data packet sending thread and cleaning memory data at the same time; if the sub-data packet number needing to be retransmitted is received, the sub-data packet with the corresponding number is preferentially sent; if not, continuing to send the next sub-data packet in sequence;
after the data packet receiving thread receives a current sub data packet sent by a serial port, deleting the number of the corresponding sub data packet in the queue according to the number x of the current sub data packet, simultaneously judging whether the queue is empty, if so, sending a file transmission completion notification to the data packet sending thread, stopping the data packet receiving thread, and simultaneously clearing memory data; if not, continuing to judge whether the sub-data packet number smaller than x exists in the queue, if so, returning the sub-data packet number to a data packet sending thread, and if not, waiting for receiving the next sub-data packet.
Preferably, when the serial port is selected, a serial port for duplex communication, such as an RS485 serial port, an RS422 serial port or an RS232 serial port, is selected.
The file transmission mode does not need to send the next sub-data packet after one sub-data packet is successfully sent, but the data packet sending thread sends the sub-data packet to the serial port at fixed intervals and receives the data packet number which is sent by the data packet receiving thread and needs to be retransmitted, and the sending process and the receiving process are carried out simultaneously, so that the problems of low communication speed and high error probability of the serial port are effectively solved.
It should be noted that if the preset time is exceeded, the data packet receiving thread does not receive the sub data packet sent by the serial port all the time, and the queue is not empty, it indicates that the communication is failed, and at this time, the data packet sending thread and the data packet receiving thread need to be stopped, and the memory data of the data packet sending thread and the data packet receiving thread needs to be cleared.
Finally, it should be noted that the above examples are only used to illustrate the technical solutions of the present invention and not to limit the same; although the present invention has been described in detail with reference to preferred embodiments, those skilled in the art will understand that: modifications to the specific embodiments of the invention or equivalent substitutions for parts of the technical features may be made; without departing from the spirit of the present invention, it is intended to cover all aspects of the invention as defined by the appended claims.
Claims (3)
1. A file transmission method based on double threads is characterized by comprising the following steps:
preparation phase
A data packet sending thread, which divides the file into n data blocks according to a fixed length, each data block is packaged into a sub data packet, the sub data packets are numbered from 1 to n according to the sequence in the file, and the number n of the sub data packets is sent to a data packet receiving thread through a serial port;
the data packet receiving thread receives the number n of the sub data packets sent by the data packet sending thread from the serial port and establishes a queue which is arranged from the number 1 to n of the sub data packets;
transmission phase
The data packet sending thread sends the data packets to the serial port at a fixed frequency according to a sending sequence from 1 to n, and simultaneously detects whether the number of the data packets needing to be retransmitted or a file transmission completion notification sent by the data packet receiving thread is received; if a file transmission completion notification is received, stopping a data packet sending thread; if the sub-data packet number needing to be retransmitted is received, the sub-data packet with the corresponding number is preferentially sent; if not, continuing to send the next sub-data packet in sequence;
after the data packet receiving thread receives the current data packet sent by the serial port, deleting the number of the corresponding data packet in the queue according to the number x of the current data packet, judging whether the queue is empty, if so, sending a file transmission completion notification to the data packet sending thread, and stopping the data packet receiving thread; if not, judging whether a sub-data packet number smaller than x exists in the queue, if so, returning the sub-data packet number to a data packet sending thread, and if not, waiting for receiving the next sub-data packet.
2. The dual-thread based file transfer method of claim 1, wherein: and if the preset time is exceeded, the data packet receiving thread does not receive the sub data packet sent by the serial port, and the queue is not empty, stopping the data packet sending thread and the data packet receiving thread.
3. The dual-thread based file transfer method according to claim 1 or 2, characterized in that: and after the data packet sending thread or the data packet receiving thread is stopped, cleaning the memory data of the corresponding thread.
Priority Applications (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710421095.8A CN107172181B (en) | 2017-06-07 | 2017-06-07 | File transmission method based on double threads |
Applications Claiming Priority (1)
Application Number | Priority Date | Filing Date | Title |
---|---|---|---|
CN201710421095.8A CN107172181B (en) | 2017-06-07 | 2017-06-07 | File transmission method based on double threads |
Publications (2)
Publication Number | Publication Date |
---|---|
CN107172181A CN107172181A (en) | 2017-09-15 |
CN107172181B true CN107172181B (en) | 2020-12-04 |
Family
ID=59825471
Family Applications (1)
Application Number | Title | Priority Date | Filing Date |
---|---|---|---|
CN201710421095.8A Active CN107172181B (en) | 2017-06-07 | 2017-06-07 | File transmission method based on double threads |
Country Status (1)
Country | Link |
---|---|
CN (1) | CN107172181B (en) |
Families Citing this family (3)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN107945430B (en) * | 2017-11-24 | 2021-09-14 | 上海动联信息技术股份有限公司 | Serial-port-based bidirectional concurrent communication method for intelligent POS machine |
CN110062295A (en) * | 2019-04-19 | 2019-07-26 | 视联动力信息技术股份有限公司 | A kind of file resource acquisition methods and system |
CN114116577B (en) * | 2022-01-29 | 2022-05-03 | 南京沁恒微电子股份有限公司 | Method and system for uploading data in real time through USB virtual serial port and USB host |
Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101656756A (en) * | 2009-09-17 | 2010-02-24 | 中国科学院声学研究所 | File transferring method with self-adaptive control of transmission speed and system thereof |
CN103685243A (en) * | 2013-11-28 | 2014-03-26 | 许继电气股份有限公司 | Fault recording data transmission method based on UDP |
CN103957169A (en) * | 2014-05-14 | 2014-07-30 | 上海复兰信息科技有限公司 | Reliable UDP achievement method based on reserve request |
CN105242908A (en) * | 2015-11-24 | 2016-01-13 | 西安烽火电子科技有限责任公司 | Method for transmitting very high frequency radio large file based on serial hardware flow control |
CN105357305A (en) * | 2015-11-13 | 2016-02-24 | 北京金山安全软件有限公司 | File sending method and device, file receiving method and device and terminal equipment |
CN106341738A (en) * | 2015-07-08 | 2017-01-18 | 杭州海康威视数字技术股份有限公司 | Streaming media network transmission bandwidth calculation method, server and system |
Family Cites Families (2)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
US8145887B2 (en) * | 2007-06-15 | 2012-03-27 | International Business Machines Corporation | Enhanced load lookahead prefetch in single threaded mode for a simultaneous multithreaded microprocessor |
US8086801B2 (en) * | 2009-04-08 | 2011-12-27 | International Business Machines Corporation | Loading data to vector renamed register from across multiple cache lines |
-
2017
- 2017-06-07 CN CN201710421095.8A patent/CN107172181B/en active Active
Patent Citations (6)
Publication number | Priority date | Publication date | Assignee | Title |
---|---|---|---|---|
CN101656756A (en) * | 2009-09-17 | 2010-02-24 | 中国科学院声学研究所 | File transferring method with self-adaptive control of transmission speed and system thereof |
CN103685243A (en) * | 2013-11-28 | 2014-03-26 | 许继电气股份有限公司 | Fault recording data transmission method based on UDP |
CN103957169A (en) * | 2014-05-14 | 2014-07-30 | 上海复兰信息科技有限公司 | Reliable UDP achievement method based on reserve request |
CN106341738A (en) * | 2015-07-08 | 2017-01-18 | 杭州海康威视数字技术股份有限公司 | Streaming media network transmission bandwidth calculation method, server and system |
CN105357305A (en) * | 2015-11-13 | 2016-02-24 | 北京金山安全软件有限公司 | File sending method and device, file receiving method and device and terminal equipment |
CN105242908A (en) * | 2015-11-24 | 2016-01-13 | 西安烽火电子科技有限责任公司 | Method for transmitting very high frequency radio large file based on serial hardware flow control |
Also Published As
Publication number | Publication date |
---|---|
CN107172181A (en) | 2017-09-15 |
Similar Documents
Publication | Publication Date | Title |
---|---|---|
EP3298824B1 (en) | Method and apparatus for managing buffer in wireless communication system | |
CN107172181B (en) | File transmission method based on double threads | |
CN106533639A (en) | Data retransmission method and device | |
CN102710758A (en) | Method for continuously transferring breakpoint of data stream based on single chip system | |
WO2010009046A1 (en) | Systems and methods for parallel communication with legacy wlan receivers | |
CN101620551A (en) | Network card interrupt control method for a plurality of virtual machines | |
CN103716133A (en) | Method for preventing data loss | |
CN104836648A (en) | Method for fast retransmission and feedback of RLC AM mode | |
CN103701843A (en) | Information synchronization data transmission method and system | |
KR20150030713A (en) | Avoiding unwanted tcp retransmissions using optimistic window adjustments | |
CN102412990B (en) | Remote sensing satellite raw data recording system with centralized management and real-time transmission functions | |
JP2013546213A (en) | MAC data service enhancement | |
CN107567107A (en) | A kind of method and device for transmitting data | |
CN103973414B (en) | A kind of data transmission method and device | |
CN104618007B (en) | A kind of synchronous satellite Transmission Control Protocol segmentation connection optimization method | |
CN115994048B (en) | Chip, communication method, system and storage medium | |
CN112929455B (en) | UDP-based data transmission method, device, equipment and readable storage medium | |
CN108886713B (en) | Data transmission method, data receiving equipment and data sending equipment | |
CN103338184A (en) | Data transmitting method and apparatus, data receiving apparatus and data transmission system | |
CN106470497A (en) | A kind of data transmission method, wireless spread-spectrum technology send and receiving entity | |
CN113992654A (en) | High-speed file transmission method, system, equipment and medium | |
US8943362B2 (en) | Control and monitoring for fast millimeter-wave link using out-of-band wireless channel | |
CN104486187B (en) | A kind of CAN communication device and method of dynamic synchronization | |
CN103338158A (en) | GOOSE message transmission delay jitter suppression method | |
US20210392187A1 (en) | Data transmission and network interface controller |
Legal Events
Date | Code | Title | Description |
---|---|---|---|
PB01 | Publication | ||
PB01 | Publication | ||
SE01 | Entry into force of request for substantive examination | ||
SE01 | Entry into force of request for substantive examination | ||
GR01 | Patent grant | ||
GR01 | Patent grant |