Overview Module Function Class Tea 3.2.4 Reference Documentation
© 2009 PDM&FC

Class TSocket

Instances of TSocket are used as client sockets. This class responds to the same interface as classes TInput and TOutput. That means that a TSocket can be used wherever a TInput or TOutput are used.

Method Summary
close
         Closes the socket by severing the connection with the remote server.
constructor
constructor host port
         Initializes the socket by connecting to a remote server.
copyTo output [byteCount]
         Copies the contents of the socket input stream into an output stream.
flush
         Flushes the output internal buffers by sending its contents into the socket output stream.
open host port
         Connects the socket to a remote server.
printf formatString [arg1 ...]
         Outputs into the socket output stream a string built from a template string, in the same way as the C printf function.
readln
         Reads a line from the socket input stream.
setLineBuffering flag
         Sets the buffering mode in the socket output stream.
write [arg1 ...]
         Sends the contents of a string into the socket output stream.
writeln [arg1 ...]
         Sends the contents of a string into the socket output stream followed by an "end of line" sequence.

Method Detail

close

TSocket close

Closes the socket by severing the connection with the remote server.

After the socket is closed it can no longer be used to perform any operation. This method should always be called to release alocated resources, like I/O buffers and file descriptors.

constructor

TSocket constructor
TSocket constructor host port

Initializes the socket by connecting to a remote server.

Parameters:
host - A string representing the name of the remote server to connect to.
port - An integer representing the port number on the remote server to connect to.

If called with no arguments the socket will not be connected. The open method must then be called to establish the connection with a remote server.

When the two host, port arguments are received a connection to that remote server is imediatly attempted.

If the connection can not be successfully established then a runtime error will occur.


copyTo

TSocket copyTo output [byteCount]

Copies the contents of the socket input stream into an output stream.

Parameters:
output - A TOutput object into which the stream contents will be copied.
byteCount - Integer representing the maximum number of bytes to copy into the the TOutput.
Returns:
A reference to the object it was called for.

The copy procedure continues either until the end of file condition is reached in the socket input stream or until byteCount bytes have been read. If there is no byteCount argument then the copy proceeds until the end of file on the input stream.

flush

TSocket flush

Flushes the output internal buffers by sending its contents into the socket output stream.

Returns:
A reference to the object it was called for.


open

TSocket open host port

Connects the socket to a remote server.

Parameters:
host - A string representing the name of the remote server to connect to. It may be in the form of an IP address.
port - An integer representing the port number on the remote server to connect to.

If the socket was already opened then it is closed before attempting to connect to the remote server.

If the connection can not be successfully established then a runtime error will occur.


printf

TSocket printf formatString [arg1 ...]

Outputs into the socket output stream a string built from a template string, in the same way as the C printf function.

Parameters:
formatString - A string object representing the format string in the way of the C printf function.
arg1 - Object of type dependent on the format string.


readln

TSocket readln

Reads a line from the socket input stream.

Returns:
The string containing the line that was read. The null object if the socket input stream has reached the end of file condition.


setLineBuffering

TSocket setLineBuffering flag

Sets the buffering mode in the socket output stream.

Parameters:
flag - A boolean object signaling if the buffering mode should be line buffered.
Returns:
A reference to the object it was called for.

When this method is called with a flag argument of true the buffering mode is set to line buffered. In line buffered mode, after a call to the a flush is implicitly performed. When flag is false then the stream is set to fully buffered mode.

write

TSocket write [arg1 ...]

Sends the contents of a string into the socket output stream.

Parameters:
arg1 - The object to be written. It may be either a string, integer or float object.
Returns:
A reference to the object it was called for.

This methods concatenates the contents of its arguments and sends the the result to the socket output stream. If one of the arguments is an integer or a float than its decimal representation is used.

writeln

TSocket writeln [arg1 ...]

Sends the contents of a string into the socket output stream followed by an "end of line" sequence.

Parameters:
arg1 - The object to be written. It may be either a string, integer or float object.
Returns:
A reference to the object it was called for.

This methods concatenates the contents of its arguments and sends the the result to the socket output stream. If one of the arguments is an integer or a float than its decimal representation is used. After writing all of the arguments it sends an "end of line" sequence.


Overview Module Function Class Tea 3.2.4 Reference Documentation
© 2009 PDM&FC
Report a bug or request new features
© 2009