Aztec® Programming Language
Version 1.1 Alpha 2

Copyright © 2010-2017, Aztec Development Group, All Rights Reserved

Download Aztec

Search        Contact Us

'Cause I can't give the best...

Unless I got... room to move.

- John Mayall

 

aztec.io.SocketStream

public class SocketStream from<StreamIO>

Base

StreamIO

SocketStream

The SocketStream class provides binary stream I/O for client socket objects. When a ServerSocket object accepts a connection, it automatically creates a ClientSocket object to communicate with the remote application. The ClientSocket object in turn creates a SocketStream object which is used to perform the actual stream I/O within the socket. When a ClientSocket object is created manually, a successful Connect() call results in the SocketStream object being automatically created in order to communicate with the remote application. As such, there is typically no need to manually create a SocketStream object, since it is automatically created for you.

 

When a Write() is performed on the socket stream, the data is sent to the remote application, and when data is received from the remote application, a Read() is performed to retrieve it.

 

Sockets are not "direct access", so the 'SetPos()' method will have no effect or meaning.

SocketStream Methods

SocketStream() Constructor for the SocketStream class
Socket() Returns the ClientSocket object associated with this stream
BytesAvailable() Virtual method to return the number of bytes available to read before end of data
EndOfStream() Virtual method to return true if currently at end of data stream
Read() Virtual method to read a single 8 byte integer from the socket
Read() Virtual method to read a single "small" integer from the socket (1, 2 or 4 bytes)
Read() Virtual method to read a single float from the socket (4 or 8 bytes)
Read() Virtual method to read a text string from the socket (default length or specific length)
Read() Virtual method to read a boolean from the socket
Read() Virtual method to read a binary buffer (stream) from the socket
Write() Virtual method to write a single 8 byte integer to the socket
Write() Virtual method to write a single "small" integer to the socket (1, 2 or 4 bytes)
Write() Virtual method to write a single float to the socket (4 or 8 bytes)
Write() Virtual method to write a single text string (default or specific length)
Write() Virtual method to write a single boolean to the socket
Write() Virtual method to write a binary buffer (stream) to the socket

Derived Classes

See Also

 


SocketStream()

public method SocketStream(ClientSocket Socket)

Parameters

ClientSocket

Client socket object associated with the stream

Return Value

None

Description

Constructor for the SocketStream class. The associated ClientSocket object is passed in. The I/O type is not specified as an argument, since a socket stream is always created as 'ReadWrite'. As mentioned above, there is typically no need to manually instantiate this class, since one is autoatically created for you within the ClientSocket class, regardless of which side of the communication link you're on.

 

SocketStream Class


Socket()

public method<ClientSocket> Socket()

Parameters

None

Return Value

Reference to CientSocket object

Description

Returns the reference to the ClientSocket object which is associated with this socket stream. That client socket object creates this socket stream object, and it uses the stream to facilitate the I/O with the remote application.

 

SocketStream Class


BytesAvailable()

public virtual method<int> BytesAvailable()

Parameters

None

Return Value

Number of bytes available to read

Description

Returns the number of bytes available to read from the socket.

 

SocketStream Class


EndOfStream()

public virtual method<bool> EndOfStream()

Parameters

None

Return Value

Returns true if at end of stream

Description

Virtual method to return the value of the "end of stream" flag. If there are no bytes available in the internal socket buffer to read, this method returns true and false if there are one or more bytes available to read.

 

SocketStream Class


Read()

public virtual method Read(int ref IntBucket, bool PeekOnly = false)

Parameters

IntBucket

Integer reference to receive the value

PeekOnly

If true, peek without reading/removing

Return Value

None

Description

Virtual method to read a single binary 8 byte integer value from the socket and copy the value into the IntBucket. If the "PeekOnly" flag is true, the value is read but the internal socket pointer position is not advanced, so the next read operation will read the same data.

 

Reading data from a socket stream should typically be performed inside a SocketReceiveEvent handler.

 

SocketStream Class


Read()

public virtual method Read(int ref IntBucket, SmallInt IntSizeEnum, bool IsSigned = true, bool PeekOnly = false)

Parameters

IntBucket

Integer reference to receive the value

IntSizeEnum

Enumeration to indicate 1, 2 or 4 byte integer

IsSigned

Treat as signed integer If true, and unsigned if false (default is false)

PeekOnly

Peek without reading/removing if true (default is false)

Return Value

None

Description

Virtual method to read a single "small" binary integer value from the socket and copy the value into the IntBucket. The size of the integer read operation is specified by IntSizeEnum, and represents 1, 2 or 4 bytes. The "IsSigned" flag is also used to affect how the binary integer buffer is interpreted, signed or unsiged. If the "PeekOnly" flag is true, the value is read but the internal socket pointer position is not advanced, so the next read operation will read the same data.

 

Reading data from a socket stream should typically be performed inside a SocketReceiveEvent handler.

 

SocketStream Class


Read()

public virtual method Read(float ref FloatBucket, bool Read32BitFloat = false, bool PeekOnly = false)

Parameters

FloatBucket

Float reference to receive the value

Read32BitFloat

Read 32 bit (4 byte) float if true (default is false)

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single binary floating point value from the socket and copy the value into the FloatBucket. The default size of the float read operation is 8 bytes, but can be changed to 4 bytes by setting the "Read32BitFloat" flag. If the "PeekOnly" flag is true, the value is read but the internal socket pointer position is not advanced, so the next read operation will read the same data.

 

Reading data from a socket stream should typically be performed inside a SocketReceiveEvent handler.

 

SocketStream Class


Read()

public virtual method Read(string ref StringBucket, bool ExtractLength = true, int ReadSize = 0, bool PeekOnly = false)

Parameters

StringBucket

String reference to receive the value

ExtractLength

Read the string length from the stream if true

ReadSize

Size of the read operation if ExtractLength is false

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single string from the socket and copy the value into the StringBucket. This supports reading a variable length string, and there are two ways of handling this. If the "ExtractLength" flag is true, the size of the string is actually read from the socket (as a 4 byte integer) and then the string read operation is dictacted by that size. If the "ExtractLength" flag is false, the "ReadSize" value is then used to dictate the length of the string to be read.

 

If the "PeekOnly" flag is true, the value is read but the socket pointer position is not advanced, so the next read operation will read the same data.

 

Reading data from a socket stream should typically be performed inside a SocketReceiveEvent handler.

 

SocketStream Class


Read()

public virtual method Read(bool ref BoolBucket, bool PeekOnly = false)

Parameters

BoolBucket

Boolean reference to receive the value

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a single binary boolean value from the socket and copy the value into the BoolBucket. It is read as a one byte value. If the "PeekOnly" flag is true, the value is read but the socket pointer position is not advanced, so the next read operation will read the same data.

 

Reading data from a socket stream should typically be performed inside a SocketReceiveEvent handler.

 

SocketStream Class


Read()

public virtual method Read(StreamIO StreamBucket, int ReadSize = 0, bool PeekOnly = false)

Parameters

StreamBucket

Stream reference to receive the data

ReadSize

Size of the binary read operation

PeekOnly

If true, read without advancing pointer

Return Value

None

Description

Virtual method to read a binary block of data from the socket and write it into the target stream (StreamBucket). The size of the read operation is specified. If the target stream supports "random access", the data is written at the current pointer position within that target stream. If the "PeekOnly" flag is true, the value is read but the socket pointer position is not advanced, so the next read operation will read the same data.

 

If the ReadSize is specified as zero, the read operation goes all the way to the end of what's available in this socket.

 

Reading data from a socket stream should typically be performed inside a SocketReceiveEvent handler.

 

SocketStream Class


Write()

public virtual method Write(int Value)

Parameters

Value

Integer value to be written

Return Value

None

Description

Virtual method to write a single 8 byte binary integer value to the socket.

 

Writing data to a socket stream results in a message being sent to the remote application containing the data that was written.

 

SocketStream Class


Write()

public virtual method Write(int Value, SmallInt IntSizeEnum)

Parameters

Value

Integer value to be written

IntSizeEnum

Enumeration to indicate 1, 2 or 4 byte integer

Return Value

None

Description

Virtual method to write a single "small" binary integer value to the socket. The size of the integer write operation is specified by IntSizeEnum, and represents 1, 2 or 4 bytes. The integer value must fit within one of the two valid ranges for the integer size that was specified. For each integer size, there is a valid "signed" range and a separate value "unsigned" range. Refer to the 'int' class documention for more details.

 

Writing data to a socket stream results in a message being sent to the remote application containing the data that was written.

 

SocketStream Class


Write()

public virtual method Write(float Value, bool Write32BitFloat = false)

Parameters

Value

Float value to be written

Write32BitFloat

Write 32 bit (4 byte) float if true (default is false)

Return Value

None

Description

Virtual method to write a single binary floating point value to the socket. The default size of the float write operation is 8 bytes, but can be changed to 4 bytes by setting the "Write32BitFloat" flag. If the "Write32BitFlag" is set, the floating point value must fit within the valid range for a 4 byte float. Refer to the 'float' class documention for more details..

 

Writing data to a socket stream results in a message being sent to the remote application containing the data that was written.

 

SocketStream Class


Write()

public virtual method Write(string Value, bool EmbedLength = true, int OverrideLength = 0)

Parameters

Value

String value to be written to stream

EmbedLength

If true, embed string length into stream before the string

OverrideLength

Override length for string to be written

Return Value

None

Description

Virtual method to write a single string to the socket. If the "EmbedLength" flag is true, the length of the string is embedded in the socket before the text string itself (as a 4 byte integer). By default, the entire string is written to the socket, but if "OverrideLength" is greater than zero, then the override length will be used instead.

 

Writing data to a socket stream results in a message being sent to the remote application containing the data that was written.

 

SocketStream Class


Write()

public virtual method Write(bool Value)

Parameters

Value

Boolean value to be written

Return Value

None

Description

Virtual method to write a single binary boolean value to the socket. It is written as a one byte integer value repesenting the enumeration index.

 

Writing data to a socket stream results in a message being sent to the remote application containing the data that was written.

 

SocketStream Class


Write()

public virtual method Write(StreamIO SourceStream, int WriteSize = 0)

Parameters

SourceStream

Source stream reference

WriteSize

Size of the binary write operation

Return Value

None

Description

Virtual method to read a binary block of data from the source stream and write it into this socket. The size of the read and write operation is specified by "WriteSize". The data is read from the current pointer position within the source stream and then written into this socket. If the WriteSize is specified as zero, the read operation from the source stream goes all the way to the end of that stream.

 

Writing data to a socket stream results in a message being sent to the remote application containing the data that was written.

 

SocketStream Class

 

Copyright © 2010-2017

Aztec Development Group

All Rights Reserved

Download Aztec