Using Delphi to design powerful server programs

Source: Internet
Author: User

Now the popularity of the network, so that the server program has been widely used, then we use Delphi how to design a strong server?

Some people say that if you want to design a server, you must use VC to design, in fact, this person said there is a certain reason, because if you want to use Delphi to design the server, to design efficient servers do not use the Delphi to bring most of the control (preferably do not use Delphi control), Why, then? Now I'll tell you. In this way, you use the API to design the server, there is no big difference with VC.

Use Delphi to design the server program, whether to use the form message mode or the completion port mode, which depends mainly on the number of user connections. If your user connection is less than 1000 people, and the amount of data processed is small, you can use the form of message mode for server development, and if greater than 1000, it is best to use the completion port to develop the server. I recommend that you use the completion port mode, because you can not guarantee the number of your users do not change, and because your server if running for a period of time there is no problem, it is best to make a win service program, so as to ensure that the later maintenance is relatively small.

Now introduce you to the development of Delphi server when you need to pay attention to the place:

1 do not use string variables in your program

This is also found in the actual development process, when I first developed, in order to simplify, the use of a large number of string variables to develop the program, but the program is always running for a period of time after the problem, and then find the reason is not very clear to the Internet to check the data, found that someone introduced do not use string to do variables, All of your own program to modify the problem of the group is basically solved.

2 using fast encryption algorithms such as XOR encryption or DES encryption algorithms

The server must be encrypted when it is delivered with the client, but what type of encryption algorithm is used? Do not use a large number of algorithms such as RSA algorithm, it is best to use XOR encryption or DES transposition encryption algorithm, this is mainly to meet the requirements of ordinary encryption ciphertext, but also to ensure that the server's operation speed. You can also use the RSA encryption text, but this can cause server processing to slow down, and if you encounter a lot of processing time, it is easy for the server to reject the server.

3 using the original ADO function to connect to the database

Server programs are usually associated with the database, then use the Delphi development, usually use the control of ADO to make, but if you learn the ADO manual will find that the server does not need control to complete the operation of the data. You can do this directly by using the appropriate functions of ADO. Mainly because the server program and the database are usually simpler operations, not very complex. So use the original ADO mode is OK. This also reduces the problems caused by ADO controls.

4 should use "Pool" more

The server in the design process, must be a large number of variable support, if not using the concept of pool, your program will create and release variables in the process of wasting a lot of time. And the problem is easy to come by. Try not to create and release variables in the design process, and if you can consider the variables, create them at the start of the run. This will speed up the program and reduce conflicts. Specific how to use the pool this technology, later have time to consider writing an introduction.

5 skilled use of pointer operation

If you are unfamiliar with pointer operation, you can hardly design efficient server, if you want to really understand the concept of pointers, for the design of the server is a menace.

For example, if you use recv to receive data to buffer, you need to decrypt the operation, you can use the following method:

var
  a,b:array [1..8] of byte;
  i :integer;
  ResultBuffer :array [1..Max] of byte;
begin
  for i := 1 to Sizeof(Buffer) div 8 do
  begin
   move(Buffer[(i-1)*8+1],a,8);
   Des(a,b,true); //这里使用DES加解密处理
   move(b,ResultBuffer[(i-1)*8+1],8);
  end;
end

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.