Using the TCP/IP system layer
TCP/IP is supported by three primary classes implemented at the system layer:
AbtTCPInetHost
AbtTCPPort
AbtSocket
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.
Defining and connecting 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.
1. Create an instance of the AbtTCPInetHost class.
You need to know either the name or address of the remote host as illustrated in the following examples:
sample 
host :=AbtTCPInetHost getHostById: 'LANCELOT'.
host :=AbtTCPInetHost getHostById: '9.67.226.121'.
2. Define the host port.
To define the port that is used at the remote host by this application, do the following:  
address := AbtTCPPort usingHost: host portNumber: 1201.
3. Create and initialize a socket.
To create a socket and initialize it, do the following:  
(socket := AbtSocket newStreamUsingPort: address) socket.
4. Initiate the connection.
To initiate the connect, do the following:  
result := socket connect.
Sending and receiving data
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.
Ending the connection
To end the connection to the remote host, do the following.
result := socket soclose.
Handling Errors
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 ].
Last modified date: 01/29/2015