Standard socket and socket in Delphi

Source: Internet
Author: User

Application of standard socket Program The framework is as follows:
Server Side: socket () [Create a socket] -- BIND () [Same server address bonding] -- Listen () -- accept () -- block wait -- read () [accept messages, in Windows, the method is send (TCP), or sendto (UDP)] -- process service request -- write () [Send message, in windows, the method is send (TCP) or sendto (UDP ).
The client side is relatively simple: socket () -- connect () [connects to a specific server through a certain port, which is a connection with the server] -- write () -- read ().
The socket can be based on TCP, UDP, and other protocols, such as IPX, SPX, and decnet. When creating a socket, you can specify the new socket type. BIND () is used to bind the same server address. If a host has only one IP address, the binding function is actually redundant. Listen () starts listening to the network. Accept () is used to accept connections. The returned value is the socket that maintains contact with the client.
In Delphi, the socket in Windows is effectively encapsulated. In Delphi, based on its inheritance relationship, there are two types of hierarchy:
I. tcomponent -- tabstractsocket -- tcustomsocket -- tcustomserversocket -- tserversocket
Tcomponent -- tabstractsocket -- tcustomsocket -- tclientsocket
Ii. inherit from tobject directly:
Tobject -- tcustomwinsocket -- tserverwinsocket
Tobject -- tcustomwinsocket -- tclientwinsocket
Tobject -- tcustomwinsocket -- tserverclientwinsocket
We can see that the first type is based on tcustomsocket, and the second type is based on tcustomwinsocket. The first type is based on tcomponet, and the second type is directly based on tobject. Therefore, if you are familiar with socket and want to write console programs, you can use the tcustomwinscoket class.
As you can see in uses, they are all in scktcomp. in pas, while in schtcomp. in pas, it contains Winsock. PAS file. If you continue to go deep into the Winsock file, you can find all the basic methods of Windows Socket.

In fact, if you understand the application framework of the standard socket, you will be able to write the Socket Application Using DELPHI. This does not mean that you must understand the standard functions in the complex socket and there is no need, because delphi has made a good encapsulation for you, which is also the strength of Delphi. You only need to understand the basic framework a little bit.

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.