Project Summary and difficult replay, project summary and difficult Replay

Source: Internet
Author: User

Project Summary and difficult replay, project summary and difficult Replay
Project Summary and difficulty Replay

1. General framework of the program
A computing program is a client that establishes a socket connection with the server and obtains the data to be computed in real time.
The computing result is written into the table corresponding to the oracle database for reading and displaying the result on the foreground interface.

2. Position and Function of the computing module
Complete data socket communication, data receiving, data parsing, computing, and result writing to the database.

3. Use Technology
Socket communication, thread synchronization, OTL, Oracle database query, STL.

3. Technical difficulties
1) Simple Socket communication protocol implementation

Finally, socket recv is selected for Loop Blocking receiving. The data is implemented through the struct, And the header and body are defined,
The number of headers containing the body.

2) package Parsing
This is also a problem with my work two years ago. That is, the package size is accumulated before parsing.
How old is it?
Implementation found: If the value is set to 4 K or 8 K, it is easy to cause parsing dislocation, resulting in an error or a string of one byte will cause the program to crash.
Implement the loop monitoring Buffer by yourself, and delete the resolution as much as possible to record the new starting point value and the remaining Buffer size.
You can use the first-in-first-out dual-end queue for management. That is:
Join: enter a package;
Resolution: parse the accumulated 10 packets (set the value according to the package size) to avoid the phenomenon of remaining bytes.
Once an offset or error occurs, the parsed data may be abnormal or out of bounds.
Team out: leave after parsing a package.
Implementation Method: deque push_back, pop, empty, and size functions.

3) multi-thread synchronization
The main thread is responsible for calculating the parsed data and writing the results to the Oracle database through OTL.
The sub-thread is responsible for receiving and parsing data from the Socket.
There is a synchronization relationship between the main thread and the sub-thread through Event.
The main thread can perform computation and write operations only after the sub-thread receives and parses the data. It accepts resolution and then computes and writes data to the database.
At the same time, the sub-thread is notified to continue parsing after the main process is written.

4) vector cleanup
Because the program executes cyclically and every result is in push_back vector, because initialization at the entrance is not performed
The more cycles the program executes later. Until an error is reported.

Am5: 07 Si On the Beijing hotel bed

Author: Mingyi Tianxia
Reprinted please indicate the source, original address: http://blog.csdn.net/laoyang360/article/details/46322759
If this article is helpful to you, click 'ding' to support it. Your support is the greatest motivation for my persistence in writing. Thank you!


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.