Type: Integer
Availability: Read-only at any time
The state property of the Connection class contains the state of the connection. Methods can be called only in the appropriate state and they can cause the connection state to change.
The values of the state property are listed in the following table.
Connection Class Constant | Integer Value |
---|---|
Connected | 2 |
Connecting (or listening) | 1 |
Disconnected | 0 |
Disconnecting | 3 |
The open, openAsynch, listen, listenAsynch, listenContinuous, and listenContinuousAsynch methods can be called only when the state property is set to Disconnected (0). When these methods are called, the state is changed to Connecting (1). The connection state changes to Connected (2) when the connection is open or a listen method completes.
On asynchronous calls, the state may not change immediately, and it may remain Disconnected (0) for a short period until JADE has rescheduled the request.
The getMaxMessageSize, readBinary, readBinaryAsynch, writeBinary, and writeBinaryAsynch methods can be called only when the state of the connection is connected; that is, this property is set to Connected (2).
The close and closeAsynch methods can be called when the connection is in any state.
The code fragment in the following example shows the use of the state property.
// Sets the TCP to listen on the current port. If a connection is made, // sets the status bar to read 'connected' and fills the text boxes with // the IP address and name information. tcp.listen(); if tcp.state = Connection.Connected then statusLine1.caption := "Connected"; textBoxLocalIP.text := tcp.localIpAddress; textBoxRemoteIP.text := tcp.remoteIpAddress; textBoxName.text := tcp.name; endif;