TCP/IP is supported by three primary classes implemented at the system layer:
In addition, if an error occurs, then an instance of the AbtTCPError class will be returned:
The following sections discuss how you use these classes to establish a connection between your application and a remote host.
The AbtTCPInetHost object represents the remote host that your application is going to communicate with. Defining and connecting to a remote host is a four-step process.
You need to know either the name or address of the remote host as illustrated in the following examples::
host :=AbtTCPInetHost getHostById: 'LANCELOT'. host :=AbtTCPInetHost getHostById: '9.67.226.121'.
To define the port that is used at the remote host by this application, do the following:
address := AbtTCPPort usingHost: host portNumber: 1201.
To create a socket and initialize it, do the following:
(socket := AbtSocket newStreamUsingPort: address) socket.
To initiate the connect, do the following:
result := socket connect.
Once you have established a connection you can send and receive data as needed.
To send data, do the following:
result:= socket sendMessage: data.
To receive data, do the following:
result:= socket receive.
To end the connection to the remote host, do the following.
result := socket soclose.
It is possible for errors to occur because of failures in the network or incorrect logic in either the client or server application. Because of this, it is a good practice to test for errors after each message is sent. Checking for errors is handled as follows:
result isCommunicationsError ifTrue: [ result display ].