Delphi4 Winsocket Programming
Maybe you have admired the powerful and technological advanced technology of web application software such as Microsoft's IE browser. Maybe you have no ability to develop such a complex large system, but don't worry, here you can give you an opportunity to practice. It is to learn to write TCP / IP-based applications with Delphi's Winsocket. It is assumed that you have been preliminarily familiar with the Delphi development tool. We can imagine that if you write a program that implements communication with the remote computer from the most original start, you must have a comprehensive familiarity and master of the relevant network protocol, the underlying knowledge of the system, and the network software and hardware technology, however this is short It is not an easy task to most people. Fortunately, Delphi's network component library provides us with components that implement network communication, which encapsulates the details of complex concrete implementation. The ClientSocket and Serversocket components make us easily write their own network communication and resource sharing programs. Steps to write a Winsocket program in Delphi 4.0 is: 1) Winsocket component property settings; 2) Establish a connection to remote computers; 3) Data transmission between computers; do these three steps in detail below. One. Winsocket Properties Settings Delphi 4.0 WinSocket is divided into two components: ClientSocket and Serversocket. They are components of the client and server, respectively. That is, the clientSocket component is used in the client program, and the ServerSocket component is used on the server. By communication between the two components, a simple communication program can be implemented in addition to the auxiliary application code. Of course, in the client program, the client program can act as a server, you can respond to the request of other client programs. If you are writing a server-side program, you must set the port properties of the ServerSocket component. This parameter is set, because multiple server programs may be run on the same computer, and they may always constantly accept connection requests from remote client programs. If you are trying to send an email, the system is connected to another server program, and your email will definitely not send it normally. So you must set a suitable port number Port on the ServerSocket component on the server program. You can also set the service property that indicates the type of service provided by ServerSocket, such as ftp, http, and more. Then set the Active property to TRUE. If you are writing a client program, you have more properties of the ClientServer component. The Port property should be set to consistent with the value of the server-side port attribute. In addition, the properties of the Host must be set correctly, it is a read-only properties, not available when design. It indicates the host name of the remote server to connect to the client program. You can also set the address attribute, which is the IP address of the remote host. If these two properties are set, the system will use the Host property, and the IP address set by the Address property is invalid. Two. Establishing a connection with a remote computer to perform data transfer between remote computer systems, first must establish a connection between the two hosts of the communication. The server-side ServerSocket component calls the Open method to initialize the socket connection, and set the Active property to True, set the ServerSocket component to the listening mode, and detect whether there is a connection request at any time. If the server accepted the client's connection request, trigger the onaccept event, the following code is to process the work to be done after the connection is accepted.