Libraries.Network.SocketConnection Documentation

This class is used to manage a Transmission Control Protocol (TCP) connection. This class is for a client connecting to a server. There are actions to open or close a TCP connection and send or receive data. Note that this class blocks when reading data and will block until data has been read.

Example Code

use Libraries.Network.SocketConnection

SocketConnection con
con:Open("time.nist.gov", 13)
//The server sends a linefeed first so read it first
con:Read(1)
// outputs the current time sent from server
output con:ReadLine()

Inherits from: Libraries.Language.Object

Actions Documentation

AvailableBytes()

When a read is attempted and a message is received there will be bytes left in the input stream. This action returns how many more bytes are left in the stream. If there are 0 bytes and a Read is attempted then the program will block until bytes are received.

Return

integer: The number of bytes currently in the socket's input stream. If no read has been attempted this will return 0.

Close()

This action closes the connection to the server.

Compare(Libraries.Language.Object object)

This action compares two object hash codes and returns an integer. The result is larger if this hash code is larger than the object passed as a parameter, smaller, or equal. In this case, -1 means smaller, 0 means equal, and 1 means larger. This action was changed in Quorum 7 to return an integer, instead of a CompareResult object, because the previous implementation was causing efficiency issues.

Parameters

Return

integer: The Compare result, Smaller, Equal, or Larger.

Example

Object o
Object t
integer result = o:Compare(t) //1 (larger), 0 (equal), or -1 (smaller)

Equals(Libraries.Language.Object object)

This action determines if two objects are equal based on their hash code values.

Parameters

Return

boolean: True if the hash codes are equal and false if they are not equal.

Example

use Libraries.Language.Object
use Libraries.Language.Types.Text
Object o
Text t
boolean result = o:Equals(t)

GetHashCode()

This action gets the hash code for an object.

Return

integer: The integer hash code of the object.

Example

Object o
integer hash = o:GetHashCode()

Open(text hostname, integer port)

This action Opens a connection to a server on a specified port

Parameters

  • text hostname: The name of the server to connect to. Either an IP address or name
  • integer port: The port number to connect to

Example


use Libraries.Network.SocketConnection

SocketConnection con
con:Open("time.nist.gov", 13)

Read(integer numberOfBytes)

This action reads a specified number of bytes and returns the result as text

Parameters

  • integer numberOfBytes: the number of bytes to attempt to read

Return

text: The bytes read from the server as text

ReadBytes(integer numberOfBytes)

This action reads a specified number of bytes and returns the result as an array of bytes

Parameters

  • integer numberOfBytes: the number of bytes to attempt to read

Return

Libraries.Containers.ByteArray: The bytes read from the server as a ByteArray

ReadLine()

This action reads input from the server until a null character or new line is read. Note that because of the nature of sockets this action will not stop until one of those characters is read. If there are no more bytes to read then this action will block until more input is received.

Return

text: Returns input from the server up until the first new line character is read

Write(text outputText)

This action sends data to the connected server

Parameters

  • text outputText: The message to send to the server

WriteBytes(Libraries.Containers.ByteArray bytes)

This action sends bytes to the connected server

Parameters