I have recently seen someone to ask someone to program how to use BCB's TServersocket and TclientSocket, so I decided to tell me some of my programming experience, so that everyone can master their usage as soon as possible.
First, you have to talk about some of their settings (properties): Several property Active of TSERVERSOCKET Active is working status, set it to Ture or False to start and stop listening. The port of this machine listening can be set to a number of larger than 1024; the work mode of the Servertype server has two options, one is a STNONBLOCKING non-blocking method, one is a StthreadBlocking thread blocking method, default is a non-blocking method. It is relatively simple to program with non-blocking mode (I personally think), with an occlusion method to control the transceiver with a thread. ThreadCachesize buffer threads are valid when Servertype is stthreadblocking. Several attributes of TclientSocket Active are working status, set it to TURE or FALSE to establish or disconnect with the server. The computer name of the Host Server (ServerSocket) is a string Address server (Serversocket) The CLIENTTYPE client's work mode is a ctnonblocking non-blocking method. One is a ctblocking blocking method, the default is a non-blocking method Port with the server ( ServerSocket) Connected port, this port is the server's listening port in Setting ClientSocket (Host) IP address is equivalent, but the host name requires the network to have DNS (Domain Name Resolution Service) server, and The host name is slower than the speed of the IP address of the host. It is recommended to connect with Serversocket with Address.
After setting all the properties, the ServerSocket control can be listened by setting its Active attribute to True. ClientSocket can be connected to Serversocket by setting its Active property. The connection can be communicated. Some events will be generated during this process, and they talk about their respective events.
Several events of TSERVERSOCKET onaccept When a customer is successful after successful service, this connection can be used after generating this event, and this customer can be transmitted and received. OnClientConnect An event is generated when a customer is establishing a connection with the server, where you can decide whether to accept this connection. OnClientDisconnect Annab this event when a customer is disconnected with the server, you need to do some processing here, such as clearing the secondary connection from the connection list. OnClienTerror generates this event when the customer occurs in the server, in which events you can block the system's error prompts by setting ERRORCODE = 0. This will avoid annoying English errors. According to the different value of ErrorEvent, it has a few incorrect type EeGeneral unknown error EESEND Send data. Eereceive receives data. EECONNECT Customer requests the error EEDISCONNECT customer Disconnect error EEACCEPT An error occurred while a customer is generally. When an error occurs, the customer's connection is already unavailable, and the connection failed to connect to this customer. OnClientRead generates this event when the server receives the data sent by the client. The data received by the client is performed here. OnClientWrite generates this event when the server sends data. Several events of TclientSocket
ONCONNECT will generate this event after the server (ServerSocket) is successfully connected, and this event will only be used, and the data can be sent to ServerSocket. OnConnecting is connected to the server to generate this event. OnDisconnect is disconnected with the server, this event is generated. After generating this event, the Active property of the clientSocket is false. At this time, this connection is not available, and the connection must be re-connected to send data to the server. OneRror generates this event when Socket occurs, and the meaning of this event is exactly the same as the ERROR event of ServerSocket, but it does not have an eeaccept error. OnRead generates this event when the data sent by the server is received. ONWRITE generates this event when data is sent to the server.