Package com.quanser.communications
Class QuanserStream
java.lang.Object
com.quanser.communications.QuanserStream
The Quanser Stream API is a generic buffered communication
protocol API based upon the Quanser Communications API.
-
Nested Class Summary
Modifier and TypeClassDescriptionstatic enum
Enumerates the different byte orders.static enum
Enumerates the different character formats available for textual communications.static class
Defines the flags used by thepoll
method. -
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionaccept()
Accepts a connection to a listening communication stream by a client and uses default send and receive buffer sizes.accept
(int sendBufferSize, int receiveBufferSize) Accepts a connection to a listening communication stream by a client.void
close()
Closes the stream.void
closeAll()
Closes all streams currently connected or listening.void
Connects to a server listening on the given URI using blocking I/O and default send and receive buffer sizes.boolean
Connects to a server listening on the given URI using blocking or non-blocking I/O and default send and receive buffer sizes.boolean
Connects to a server listening on the given URI using blocking or non-blocking I/O.void
Connects to a server listening on the given URI using blocking I/O.void
Connects to a server listening on the given URI using blocking I/O and default send and receive buffer sizes.boolean
Connects to a server listening on the given URI using blocking or non-blocking I/O and default send and receive buffer sizes.boolean
Connects to a server listening on the given URI using blocking or non-blocking I/O.void
Connects to a server listening on the given URI using blocking I/O.boolean
flush()
Flushes the stream send buffer to the underlying communication channel.Returns the character format of the stream.Returns anInputStream
object for thisQuanserStream
.Returns anOutputStream
object for thisQuanserStream
.int
ignore
(int numBytes) Reads the specified number of bytes from the stream and discards them.void
Establishes a listening server stream which listens on the given URI using blocking I/O.void
Establishes a listening server stream which listens on the given URI using blocking or non-blocking I/O.void
Establishes a listening server stream which listens on the given URI using blocking I/O.void
Establishes a listening server stream which listens on the given URI using blocking or non-blocking I/O.int
poll
(double timeout, int flags) Polls the stream for events, such as whether it is possible to send or receive without blocking.int
receive
(byte[] buffer) Reads the specified number of 8-bit integers (i.e., bytes) from the stream.int
receive
(double[] buffer) Reads the specified number of 64-bit, double-precision, floating-point numbers (i.e., doubles) from the stream.int
receive
(float[] buffer) Reads the specified number of 32-bit, single-precision, floating-point numbers (i.e., floats) from the stream.int
receive
(int[] buffer) Reads the specified number of 32-bit integers (i.e., ints) from the stream.int
receive
(long[] buffer) Reads the specified number of 64-bit integers (i.e., longs) from the stream.int
receive
(short[] buffer) Reads the specified number of 16-bit integers (i.e., shorts) from the stream.int
receiveArray
(byte[] buffer) Reads an array of 8-bit integers (i.e., bytes) from the stream.int
receiveArray
(double[] buffer) Reads an array of 64-bit, double-precision, floating-point numbers (i.e., doubles) from the stream.int
receiveArray
(float[] buffer) Reads an array of 32-bit, single-precision, floating-point numbers (i.e., floats) from the stream.int
receiveArray
(int[] buffer) Reads an array of 32-bit integers (i.e., ints) from the stream.int
receiveArray
(long[] buffer) Reads an array of 64-bit integers (i.e., longs) from the stream.int
receiveArray
(short[] buffer) Reads an array of 16-bit integers (i.e., shorts) from the stream.int
send
(byte[] buffer) Writes the specified number of 8-bit integers (i.e., bytes) to the stream send buffer.int
send
(double[] buffer) Writes the specified number of 64-bit, double-precision, floating-point (i.e., doubles) to the stream send buffer.int
send
(float[] buffer) Writes the specified number of 32-bit, single-precision, floating-point (i.e., floats) to the stream send buffer.int
send
(int[] buffer) Writes the specified number of 32-bit integers (i.e., ints) to the stream send buffer.int
send
(long[] buffer) Writes the specified number of 64-bit integers (i.e., longs) to the stream send buffer.int
send
(short[] buffer) Writes the specified number of 16-bit integers (i.e., shorts) to the stream send buffer.int
sendArray
(byte[] buffer) Writes the specified array of 8-bit integers (i.e., bytes) to the stream send buffer.int
sendArray
(double[] buffer) Writes the specified array of 64-bit, double-precision, floating-point numbers (i.e., doubles) to the stream send buffer.int
sendArray
(float[] buffer) Writes the specified array of 32-bit, single-precision, floating-point numbers (i.e., floats) to the stream send buffer.int
sendArray
(int[] buffer) Writes the specified array of 32-bit integers (i.e., ints) to the stream send buffer.int
sendArray
(long[] buffer) Writes the specified array of 64-bit integers (i.e., longs) to the stream send buffer.int
sendArray
(short[] buffer) Writes the specified array of 16-bit integers (i.e., shorts) to the stream send buffer.int
sendByte
(byte value) Writes a single 8-bit integer (i.e., byte) to the stream send buffer.int
sendDouble
(double value) Writes a single 64-bit, double-precision, floating-point (i.e., double) to the stream send buffer.int
sendFloat
(float value) Writes a single 32-bit, single-precision, floating-point (i.e., float) to the stream send buffer.int
sendInt
(int value) Writes a single 32-bit integer (i.e., int) to the stream send buffer.int
sendLong
(long value) Writes a single 64-bit integer (i.e., long) to the stream send buffer.int
sendShort
(short value) Writes a single 16-bit integer (i.e., short) to the stream send buffer.void
setByteOrder
(QuanserStream.ByteOrder byteOrder) Configures the byte order used by methods that send and receive various data types, or arrays of types.void
Configures whether the methods that send and receive characters convert between the local character format and another character format when reading and writing to the underlying communication channel.void
setSwapBytes
(boolean swap) Configures whether the methods that send and receive various data types, or arrays of types, swap the bytes in the individual values in order to account for endian differences between the client and server.void
shutdown()
Shuts down send and/or receive operations in preparation for closing the stream.
-
Constructor Details
-
QuanserStream
public QuanserStream()Constructs aQuanserStream
object. The object is not connected or listening. One of theconnect
orlisten
methods must be called before using the other methods of this object.
-
-
Method Details
-
getInputStream
Returns anInputStream
object for thisQuanserStream
. If this input stream has an associated channel then the resulting input stream delegates all of its operations to the channel. If the channel is in non-blocking I/O mode then the input stream'sInputStream
operation will throw anIllegalBlockingModeException
.- Returns:
- An
InputStream
object for reading bytes from thisQuanserStream
. - Throws:
IllegalBlockingModeException
- If the underlying stream channel is in non-blocking I/O mode.
-
getOutputStream
Returns anOutputStream
object for thisQuanserStream
. If this output stream has an associated channel then the resulting output stream delegates all of its operations to the channel. If the channel is in non-blocking I/O mode then the output stream'sgetOutputStream()
operation will throw anIllegalBlockingModeException
.- Returns:
- An
OutputStream
object for writing bytes to thisQuanserStream
. An output stream accepts output bytes and sends them to some sink. - Throws:
IllegalBlockingModeException
- If the underlying stream channel is in non-blocking I/O mode.
-
listen
Establishes a listening server stream which listens on the given URI using blocking or non-blocking I/O. This method establishes a server stream which listens on the given URI. The URI specifies the protocol, address, port and options associated with the server stream. The Stream API uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URI string indicating the stream on which to listen.nonBlocking
- Set totrue
to preventaccept
calls from blocking. Any client connections accepted will also be non-blocking. If this parameter is set tofalse
then theaccept
call will block until a client connects orshutdown
is invoked, and any client connections accepted will also use blocking I/O.- Throws:
IOException
- Failed to listen on the given URI. If a listening stream cannot be opened then an exception is thrown. This situation typically arises if the underlying protocol cannot acquire the resources it needs. For example, the TCP/IP driver may not be able to listen on a given port because another server is already using that port.URISyntaxException
- Invalid URI specified.
-
listen
Establishes a listening server stream which listens on the given URI using blocking or non-blocking I/O. This method establishes a server stream which listens on the given URI. The URI specifies the protocol, address, port and options associated with the server stream. The Stream API uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URI indicating the stream on which to listen.nonBlocking
- Set totrue
to preventaccept
calls from blocking. Any client connections accepted will also be non-blocking. If this parameter is set tofalse
then theaccept
call will block until a client connects orshutdown
is invoked, and any client connections accepted will also use blocking I/O.- Throws:
IOException
- Failed to listen on the given URI. If a listening stream cannot be opened then an exception is thrown. This situation typically arises if the underlying protocol cannot acquire the resources it needs. For example, the TCP/IP driver may not be able to listen on a given port because another server is already using that port.URISyntaxException
- Invalid URI specified.
-
listen
Establishes a listening server stream which listens on the given URI using blocking I/O. This method establishes a server stream which listens on the given URI. It uses blocking I/O. To use non-blocking I/O, use thelisten(String, boolean)
method. The URI specifies the protocol, address, port and options associated with the server stream. The Stream API uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URI string indicating the stream on which to listen.- Throws:
IOException
- Failed to listen on the given URI. If a listening stream cannot be opened then an exception is thrown. This situation typically arises if the underlying protocol cannot acquire the resources it needs. For example, the TCP/IP driver may not be able to listen on a given port because another server is already using that port.URISyntaxException
- Invalid URI specified.
-
listen
Establishes a listening server stream which listens on the given URI using blocking I/O. This method establishes a server stream which listens on the given URI. It uses blocking I/O. To use non-blocking I/O, use thelisten(URI, boolean)
method. The URI specifies the protocol, address, port and options associated with the server stream. The Stream API uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URI indicating the stream on which to listen.- Throws:
IOException
- Failed to listen on the given URI. If a listening stream cannot be opened then an exception is thrown. This situation typically arises if the underlying protocol cannot acquire the resources it needs. For example, the TCP/IP driver may not be able to listen on a given port because another server is already using that port.URISyntaxException
- Invalid URI specified.
-
connect
public boolean connect(String uri, boolean nonBlocking, int sendBufferSize, int receiveBufferSize) throws IOException, URISyntaxException Connects to a server listening on the given URI using blocking or non-blocking I/O. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URIString
indicating the listening stream to which to connect.nonBlocking
- Set totrue
to make the client connection use non-blocking I/O. Otherwise blocking I/O will be used. If thenonBlocking
flag is set tofalse
, then this method will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely. If thenonBlocking
flag is set totrue
, then this method will not block. If the connection is completed immediately thentrue
is returned. If the connection cannot be completed immediately thenfalse
is returned. In this case, the connection may be completed using thepoll(double, int)
method with thePollFlag.connect
flag.sendBufferSize
- The size of the buffer to use for sending data over the stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.receiveBufferSize
- The size of the buffer to use for receiving data over the stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.- Returns:
- This method returns
true
if the connection is established. If non-blocking I/O is being used, then it may also returnfalse
, which indicates that the connection is in progress but has not yet been completed. Finish establishing the connection, in this case, by using thepoll(double, int)
method with thePollFlag.connect
flag. - Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
public boolean connect(URI uri, boolean nonBlocking, int sendBufferSize, int receiveBufferSize) throws IOException, URISyntaxException Connects to a server listening on the given URI using blocking or non-blocking I/O. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URI indicating the listening stream to which to connect.nonBlocking
- Set totrue
to make the client connection use non-blocking I/O. Otherwise blocking I/O will be used. If thenonBlocking
flag is set tofalse
, then this method will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely. If thenonBlocking
flag is set totrue
, then this method will not block. If the connection is completed immediately thentrue
is returned. If the connection cannot be completed immediately thenfalse
is returned. In this case, the connection may be completed using thepoll(double, int)
method with thePollFlag.connect
flag.sendBufferSize
- The size of the buffer to use for sending data over the stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.receiveBufferSize
- The size of the buffer to use for receiving data over the stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.- Returns:
- This method returns
true
if the connection is established. If non-blocking I/O is being used, then it may also returnfalse
, which indicates that the connection is in progress but has not yet been completed. Finish establishing the connection, in this case, by using thepoll(double, int)
method with thePollFlag.connect
flag. - Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
Connects to a server listening on the given URI using blocking or non-blocking I/O and default send and receive buffer sizes. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver.- Parameters:
uri
- AString
URI indicating the listening stream to which to connect.nonBlocking
- Set totrue
to make the client connection use non-blocking I/O. Otherwise blocking I/O will be used. If thenonBlocking
flag is set tofalse
, then this method will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely. If thenonBlocking
flag is set totrue
, then this method will not block. If the connection is completed immediately thentrue
is returned. If the connection cannot be completed immediately thenfalse
is returned. In this case, the connection may be completed using thepoll(double, int)
method with thePollFlag.connect
flag.- Returns:
- This method returns
true
if the connection is established. If non-blocking I/O is being used, then it may also returnfalse
, which indicates that the connection is in progress but has not yet been completed. Finish establishing the connection, in this case, by using thepoll(double, int)
method with thePollFlag.connect
flag. - Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
Connects to a server listening on the given URI using blocking or non-blocking I/O and default send and receive buffer sizes. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver.- Parameters:
uri
- A URI indicating the listening stream to which to connect.nonBlocking
- Set totrue
to make the client connection use non-blocking I/O. Otherwise blocking I/O will be used. If thenonBlocking
flag is set tofalse
, then this method will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely. If thenonBlocking
flag is set totrue
, then this method will not block. If the connection is completed immediately thentrue
is returned. If the connection cannot be completed immediately thenfalse
is returned. In this case, the connection may be completed using thepoll(double, int)
method with thePollFlag.connect
flag.- Returns:
- This method returns
true
if the connection is established. If non-blocking I/O is being used, then it may also returnfalse
, which indicates that the connection is in progress but has not yet been completed. Finish establishing the connection, in this case, by using thepoll(double, int)
method with thePollFlag.connect
flag. - Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
public void connect(String uri, int sendBufferSize, int receiveBufferSize) throws IOException, URISyntaxException Connects to a server listening on the given URI using blocking I/O. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver. This method uses blocking I/O. Hence, it will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely.- Parameters:
uri
- AString
URI indicating the listening stream to which to connect.sendBufferSize
- The size of the buffer to use for sending data over the stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.receiveBufferSize
- The size of the buffer to use for receiving data over the stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.- Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
public void connect(URI uri, int sendBufferSize, int receiveBufferSize) throws IOException, URISyntaxException Connects to a server listening on the given URI using blocking I/O. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver. This method uses blocking I/O. Hence, it will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely.- Parameters:
uri
- A URI indicating the listening stream to which to connect.sendBufferSize
- The size of the buffer to use for sending data over the stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.receiveBufferSize
- The size of the buffer to use for receiving data over the stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.- Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
Connects to a server listening on the given URI using blocking I/O and default send and receive buffer sizes. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver. This method uses blocking I/O. Hence, it will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely.- Parameters:
uri
- AString
URI indicating the listening stream to which to connect.- Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
connect
Connects to a server listening on the given URI using blocking I/O and default send and receive buffer sizes. This method connects to a listening stream referenced by the given URI. The URI specifies the protocol, address, port and options associated with the server stream. TheStream
object uses the protocol to load a protocol-specific driver. This method uses blocking I/O. Hence, it will block until the connection is made. Some protocols allow a timeout to be specified in the URI or have a default timeout such that theconnect
will not block indefinitely.- Parameters:
uri
- A URI indicating the listening stream to which to connect.- Throws:
IOException
- Failed to connect to the listening stream. If the connection cannot be made then an exception is thrown. This situation typically arises if there is no server listening on the given URI. For non-blocking I/O, an exception may not be thrown until thepoll(double, int)
call if theconnect
method returnsfalse
, since the connection is still in progress in that case.URISyntaxException
- Invalid URI specified.
-
accept
Accepts a connection to a listening communication stream by a client. This method accepts a connection to a listening communication stream by a client. The client connects using one of theconnect
methods. If thelisten
method that created the stream was called withnonBlocking
flag set tofalse
then this call will block until a client connects. The client stream will also be a blocking stream. If thelisten
method that created the stream was called withnonBlocking
flag set totrue
then this call will not block. If there is no pending client connection then it will return anull
reference. Thepoll(double, int)
method may be used with thePollFlag.accept
flag to determine when a client connection is pending. In this case, the client stream returned will also be a non-blocking stream.- Parameters:
sendBufferSize
- The size of the buffer to use for sending data over the stream, in bytes. This buffer is referred to as the stream send buffer in this documentation.receiveBufferSize
- The size of the buffer to use for receiving data over the stream, in bytes. This buffer is referred to as the stream receive buffer in this documentation.- Returns:
- This method returns
This method returns a
QuanserStream
object representing a new connection to the client if the connection is established. If non-blocking I/O is being used, then it may also returnnull
, which indicates that no client connection was pending. Use thepoll(double, int)
method with thePollFlag.accept
flag to determine when a client connection is pending. - Throws:
IOException
- If the connection cannot be accepted then an exception is thrown. This situation typically arises if theaccept
method is called on a connected stream rather than a listening stream.
-
accept
Accepts a connection to a listening communication stream by a client and uses default send and receive buffer sizes. This method accepts a connection to a listening communication stream by a client. The client connects using one of theconnect
methods. If thelisten
method that created the stream was called withnonBlocking
flag set tofalse
then this call will block until a client connects. The client stream will also be a blocking stream. If thelisten
method that created the stream was called withnonBlocking
flag set totrue
then this call will not block. If there is no pending client connection then it will return anull
reference. Thepoll(double, int)
method may be used with thePollFlag.accept
flag to determine when a client connection is pending. In this case, the client stream returned will also be a non-blocking stream.- Returns:
- This method returns
This method returns a
QuanserStream
object representing a new connection to the client if the connection is established. If non-blocking I/O is being used, then it may also returnnull
, which indicates that no client connection was pending. Use thepoll(double, int)
method with thePollFlag.accept
flag to determine when a client connection is pending. - Throws:
IOException
- If the connection cannot be accepted then an exception is thrown. This situation typically arises if theaccept
method is called on a connected stream rather than a listening stream.
-
setSwapBytes
Configures whether the methods that send and receive various data types, or arrays of types, swap the bytes in the individual values in order to account for endian differences between the client and server. This method may be used to cause the bytes within shorts, integers, doubles and other data types to be swapped by theQuanserStream
object to account for endian differences between the two endpoints of the connection. TheQuanserStream
object does not detect the endianness of the peer. Calling this method with theswap
flag set totrue
causes the bytes to be swapped unconditionally. Byte swapping is only necessary when communicating between processors that use a different endianness. For example, Intel processors are little endian (LSB first) while Motorola processors tend to be big endian (MSB first). By default, no byte swapping takes place. Whether byte swapping is necessary may be determined simply by sending 0x1234 as a short and seeing if it arrives as the same number or 0x3421.- Parameters:
swap
- If this parameter istrue
then theQuanserStream
object will swap the bytes within primitive data types when sending and receiving those types, or arrays of those types. Otherwise, no byte swapping will occur.- Throws:
IOException
- If byte-swapping cannot be configured then an exception is thrown. This situation should never occur unless the underlying stream has been closed.
-
setByteOrder
Configures the byte order used by methods that send and receive various data types, or arrays of types. Byte swapping will occur in the individual values, if necessary, to achieve the desired byte ordering in order to account for endian differences between the client and server. This method may be used to cause the bytes within shorts, integers, doubles and other data types to be swapped by theQuanserStream
object to account for endian differences between the two endpoints of the connection. TheQuanserStream
object does not detect the endianness of the peer. Calling this method with the byteOrder argument set toByteOrder.littleEndian
causes the bytes to be swapped if the underlying platform is big endian. If the underlying platform is little endian then the bytes are not swapped. Calling this method with the byteOrder argument set toByteOrder.bigEndian
causes the bytes to be swapped if the underlying platform is little endian. If the underlying platform is big endian then the bytes are not swapped. Calling this method with the byteOrder argument set toByteOrder.nativeEndian
indicates that the bytes should not be swapped and the byte order of the underlying platform will be used. This byte order is the default. Byte swapping is only necessary when communicating between processors that use a different endianness. For example, Intel processors are little endian (LSB first) while Motorola processors tend to be big endian (MSB first). By default, no byte swapping takes place. Whether byte swapping is necessary may be determined simply by sending 0x1234 as a short and seeing if it arrives as the same number or 0x3421. Note that theSetSwapBytes
andSetByteOrder
methods override each other, so byte swapping will be determined by the last method called.- Parameters:
byteOrder
- The byte order to use when sending and receive data over the stream.- Throws:
IOException
- If the byte order cannot be configured then an exception is thrown. This situation should never occur unless the underlying stream has been closed.
-
setCharacterFormat
Configures whether the methods that send and receive characters convert between the local character format and another character format when reading and writing to the underlying communication channel. This method may be used to cause theQuanserStream
object to convert between character formats when sending and receiving characters (or arrays of characters). Character format conversions are only necessary when communicating between platforms that use a different character format. For example, Unix systems may use UTF-32 or UTF-8 wide characters while Windows uses UTF-16 wide characters. By default, the character format is assumed to be the same as the local character format.- Parameters:
format
- The character format to use for the underlying communication channel. The local character format is converted to and from thisformat
when communicating with the peer. If the format is set toCharacterFormat.auto
then the stream will look for a Unicode BOM character as the first character received in order to determine the character format to use.- Throws:
IOException
- If the character format cannot be configured then an exception is thrown. This situation should never occur unless the underlying stream has been closed.
-
getCharacterFormat
Returns the character format of the stream. Returns the character format of the stream. If the character format has not yet been determined thenCharacterFormat.auto
is returned. Otherwise the character format detected or set manually is returned. Character format conversions are only necessary when communicating between platforms that use a different character format. For example, Unix systems may use UTF-32 or UTF-8 wide characters while Windows uses UTF-16 wide characters. By default, the character format is assumed to be the same as the local character format.- Returns:
- The character format in use for the underlying communication channel.
- Throws:
IOException
- If the character format cannot be determined then an exception is thrown. This situation should never occur unless the underlying stream has been closed.
-
poll
Polls the stream for events, such as whether it is possible to send or receive without blocking. This method polls the stream to determine whether it is possible to send, receive, accept a connection, or complete a connection without blocking. The flags argument determines the conditions for which to check. The return value indicates the conditions which occurred. This method returns after the given timeout with a value of 0 if none of the conditions occurs. If an error occurs, then it throws aIOException
. The method will return before the timeout if at least one of the conditions occurs prior to the timeout.- Parameters:
timeout
- A relative timeout value in seconds which determines the maximum time that this method will wait for one of the conditions to occur before returning.flags
- A bit mask indicating the conditions for which to check. Combine one or more of the following flags using a bitwise-OR:PollFlag.receive
: On a listening stream, check for pending connections from clients. On a client stream, check whether there is any data available to receive.PollFlag.send
: Not valid on a listening stream. On a client stream, check whether there is any space in the stream buffer to store any data.PollFlag.flush
: Not valid on a listening stream. On a client stream, check whether it is possible to flush any more data without blocking.PollFlag.accept
: Not valid on a client stream. On a listening stream, check whether there is a pending client connection.PollFlag.connect
: Not valid on a listening stream. On a client stream, check whether the connection has completed.
- Returns:
- A bit mask containing the conditions which were satisfied. It has the same definition as the
flags
argument. If none of the specified conditions occurs before the timeout, then 0 is returned. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if one of the flags used is inconsistent with the type of stream or an error has occurred in the underlying communication channel.
-
ignore
Reads the specified number of bytes from the stream and discards them. This method receives data over a client stream. However this data is simply discarded. It is not returned to the caller. It attempts to receivenumBytes
bytes from the communication channel. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. If the connection has been closed gracefully then it returns 0 only once there is no more data to receive. Otherwise it returns the number of bytes read before the connection closed. Once all the data in the stream buffer is exhausted it will return 0 to indicate the connection has been closed. If an error occurs, then it throws aIOException
. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If no data is available at all then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of bytes received. This method does not support two threads callingignore
orreceive
at the same time. However,send
orflush
may be called by another thread at the same time asignore
. The semantics of this method differ from the BSDrecv()
socket function because it receivesnumBytes
bytes in blocking mode rather than the number of bytes that were sent in a singlesend()
call at the peer. The semantics differ because this method attempts to "read ahead" by keeping the stream buffer full, thereby minimizing the number of receive operations performed on the internal connection. Also, due to buffering of thesend
operation, the number ofsend()
calls made at the peer may not correspond to the number expected.- Parameters:
numBytes
- The number of bytes to read from the stream and ignore.- Returns:
- The number of bytes received, which may be less than
numBytes
bytes for non-blocking streams. If no more data is available and the connection has been closed gracefully then 0 is returned. If no bytes are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receive
Reads the specified number of 8-bit integers (i.e., bytes) from the stream. This method receives data over a client stream. It attempts to receivebuffer.length
8-bit integers from the communication channel. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. If the connection has been closed gracefully then it returns 0 only once there is no more data to receive. Otherwise it returns the number of 8-bit integers read before the connection closed. Once all the data in the stream buffer is exhausted it will return 0 to indicate the connection has been closed. If an error occurs, then it throws aIOException
. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If no data is available at all then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of 8-bit integers received. This method does not support two threads callingreceive
at the same time. However,send
orflush()
may be called by another thread at the same time asreceive
. The semantics of this method differ from the BSDrecv()
socket function because it receivesbuffer.length
bytes in blocking mode rather than the number of bytes that were sent in a singlesend()
call at the peer. The semantics differ because this method attempts to "read ahead" by keeping the stream buffer full, thereby minimizing the number of receive operations performed on the internal connection. Also, due to buffering of thesend
operation, the number ofsend()
calls made at the peer may not correspond to the number expected. Unlike thereceiveArray(byte[])
method, this method does not require that the internal stream receive buffer be as large as the array of 8-bit integers received. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually read.- Returns:
- The number of 8-bit integers received, which may be less than the number of elements in the
buffer
for non-blocking streams. If no more data is available and the connection has been closed gracefully then 0 is returned. If no 8-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receive
Reads the specified number of 16-bit integers (i.e., shorts) from the stream. This method receives data over a client stream. It attempts to receivebuffer.length
16-bit integers from the communication channel. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 16-bit integer that it receives or sends. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer bytes are available than the size of a 16-bit integer then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of 16-bit integers received. If the connection has been closed gracefully then it returns 0 only only if there are fewer bytes to receive than the size of a 16-bit integer. Otherwise it returns the number of 16-bit integers read before the connection closed. Once there are fewer bytes left to receive than the size of a 16-bit integer then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceive
at the same time. However,send
orflush()
may be called by another thread at the same time asreceive
. The BSD socket API has no equivalent to this method. Unlike thereceiveArray(short[])
method, this method does not require that the internal stream receive buffer be as large as the array of 16-bit integers received. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually read.- Returns:
- The number of 16-bit integers received, which may be less than the number of elements in the
buffer
for non-blocking streams. If fewer bytes are available than the size of a 16-bit integer and the connection has been closed gracefully then 0 is returned. If no 16-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receive
Reads the specified number of 32-bit integers (i.e., ints) from the stream. This method receives data over a client stream. It attempts to receivebuffer.length
32-bit integers from the communication channel. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 64-bit floating-point number received or sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer bytes are available than the size of a 32-bit integer then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of 32-bit integers received. If the connection has been closed gracefully then it returns 0 only only if there are fewer bytes to receive than the size of a 32-bit integer. Otherwise it returns the number of 32-bit integers read before the connection closed. Once there are fewer bytes left to receive than the size of a 32-bit integer then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceive
at the same time. However,send
orflush()
may be called by another thread at the same time asreceive
. The BSD socket API has no equivalent to this method. Unlike thereceiveArray(int[])
method, this method does not require that the internal stream receive buffer be as large as the array of 32-bit integers received. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually read.- Returns:
- The number of 32-bit integers received, which may be less than the number of elements in the
buffer
for non-blocking streams. If fewer bytes are available than the size of a 32-bit integer and the connection has been closed gracefully then 0 is returned. If no 32-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receive
Reads the specified number of 64-bit integers (i.e., longs) from the stream. This method receives data over a client stream. It attempts to receivebuffer.length
64-bit integers from the communication channel. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 64-bit integer that it receives or sends. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer bytes are available than the size of a 64-bit integer then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of 64-bit integers received. If the connection has been closed gracefully then it returns 0 only only if there are fewer bytes to receive than the size of a 64-bit integer. Otherwise it returns the number of 64-bit integers read before the connection closed. Once there are fewer bytes left to receive than the size of a 64-bit integer then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceive
at the same time. However,send
orflush()
may be called by another thread at the same time asreceive
. The BSD socket API has no equivalent to this method. Unlike thereceiveArray(long[])
method, this method does not require that the internal stream receive buffer be as large as the array of 32-bit integers received. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually read.- Returns:
- The number of 64-bit integers received, which may be less than the number of elements in the
buffer
for non-blocking streams. If fewer bytes are available than the size of a 64-bit integer and the connection has been closed gracefully then 0 is returned. If no 64-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receive
Reads the specified number of 32-bit, single-precision, floating-point numbers (i.e., floats) from the stream. This method receives data over a client stream. It attempts to receivebuffer.length
32-bit, single-precision, floating-point numbers from the communication channel. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 32-bit floating-point number that it receives or sends. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer bytes are available than the size of a 32-bit floating-point number then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of 32-bit floating-point numbers received. If the connection has been closed gracefully then it returns 0 only only if there are fewer bytes to receive than the size of a 32-bit floating-point number. Otherwise it returns the number of 32-bit floating-point numbers read before the connection closed. Once there are fewer bytes left to receive than the size of a 32-bit floating-point number then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceive
at the same time. However,send
orflush()
may be called by another thread at the same time asreceive
. The BSD socket API has no equivalent to this method. Unlike thereceiveArray(float[])
method, this method does not require that the internal stream receive buffer be as large as the array of 32-bit floating-point numbers received. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually read.- Returns:
- The number of 32-bit floating-point numbers received, which may be less than the number of elements in the
buffer
for non-blocking streams. If fewer bytes are available than the size of a 32-bit floating-point number and the connection has been closed gracefully then 0 is returned. If no 32-bit floating-point numbers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receive
Reads the specified number of 64-bit, double-precision, floating-point numbers (i.e., doubles) from the stream. This method receives data over a client stream. It attempts to receivebuffer.length
64-bit, double-precision, floating-point numbers from the communication channel. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 64-bit floating-point number that it receives or sends. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer bytes are available than the size of a 64-bit floating-point number then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns the number of 64-bit floating-point numbers received. If the connection has been closed gracefully then it returns 0 only only if there are fewer bytes to receive than the size of a 64-bit floating-point number. Otherwise it returns the number of 64-bit floating-point numbers read before the connection closed. Once there are fewer bytes left to receive than the size of a 64-bit floating-point number then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceive
at the same time. However,send
orflush()
may be called by another thread at the same time asreceive
. The BSD socket API has no equivalent to this method. Unlike thereceiveArray(double[])
method, this method does not require that the internal stream receive buffer be as large as the array of 64-bit floating-point numbers received. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually read.- Returns:
- The number of 64-bit floating-point numbers received, which may be less than the number of elements in the
buffer
for non-blocking streams. If fewer bytes are available than the size of a 64-bit floating-point number and the connection has been closed gracefully then 0 is returned. If no 64-bit floating-point numbers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receiveArray
Reads an array of 8-bit integers (i.e., bytes) from the stream. This method receives an array of 8-bit integers over a client stream. It differs from thereceive(byte[])
method in that it treats the entire array as an atomic unit. It either receives all of the array or none of it. This method is particularly useful for non-blocking streams because it ensures that all the values requested are read at one time. Unlike thereceive(byte[])
method, the size of the stream receive buffer must be at least as large as the array of 8-bit integers being received. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer 8-bit integers are available than the size of the entire array then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns 1. If the connection has been closed gracefully then it returns 0 only if there are fewer 8-bit integers to receive than the size of the entire array. Otherwise it returns 1. Once there are fewer 8-bit integers left to receive than the size of the entire array then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceiveArray
at the same time. However,sendArray
orflush()
may be called by another thread at the same time asreceiveArray
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer or no elements will be read.- Returns:
- Returns
1
on success. If not enough data is available and the connection has been closed gracefully then 0 is returned. If not enough 8-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receiveArray
Reads an array of 16-bit integers (i.e., shorts) from the stream. This method receives an array of 16-bit integers over a client stream. It differs from thereceive(short[])
method in that it treats the entire array as an atomic unit. It either receives all of the array or none of it. This method is particularly useful for non-blocking streams because it ensures that all the values requested are read at one time. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 16-bit integer sent or received. Unlike thereceive(short[])
method, the size of the stream receive buffer must be at least as large as the array of 16-bit integers being received. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer 16-bit integers are available than the size of the entire array then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns 1. If the connection has been closed gracefully then it returns 0 only if there are fewer 16-bit integers to receive than the size of the entire array. Otherwise it returns 1. Once there are fewer 16-bit integers left to receive than the size of the entire array then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceiveArray
at the same time. However,sendArray
orflush()
may be called by another thread at the same time asreceiveArray
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer or no elements will be read.- Returns:
- Returns
1
on success. If not enough data is available and the connection has been closed gracefully then 0 is returned. If not enough 16-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receiveArray
Reads an array of 32-bit integers (i.e., ints) from the stream. This method receives an array of 32-bit integers over a client stream. It differs from thereceive(int[])
method in that it treats the entire array as an atomic unit. It either receives all of the array or none of it. This method is particularly useful for non-blocking streams because it ensures that all the values requested are read at one time. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 32-bit floating-point number received or sent. Unlike thereceive(int[])
method, the size of the stream receive buffer must be at least as large as the array of 32-bit integers being received. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer 32-bit integers are available than the size of the entire array then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns 1. If the connection has been closed gracefully then it returns 0 only if there are fewer 32-bit integers to receive than the size of the entire array. Otherwise it returns 1. Once there are fewer 32-bit integers left to receive than the size of the entire array then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceiveArray
at the same time. However,sendArray
orflush()
may be called by another thread at the same time asreceiveArray
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer or no elements will be read.- Returns:
- Returns
1
on success. If not enough data is available and the connection has been closed gracefully then 0 is returned. If not enough 32-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receiveArray
Reads an array of 64-bit integers (i.e., longs) from the stream. This method receives an array of 64-bit integers over a client stream. It differs from thereceive(int[])
method in that it treats the entire array as an atomic unit. It either receives all of the array or none of it. This method is particularly useful for non-blocking streams because it ensures that all the values requested are read at one time. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 64-bit integer received or sent. Unlike thereceive(int[])
method, the size of the stream receive buffer must be at least as large as the array of 64-bit integers being received. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer 64-bit integers are available than the size of the entire array then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns 1. If the connection has been closed gracefully then it returns 0 only if there are fewer 64-bit integers to receive than the size of the entire array. Otherwise it returns 1. Once there are fewer 64-bit integers left to receive than the size of the entire array then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceiveArray
at the same time. However,sendArray
orflush()
may be called by another thread at the same time asreceiveArray
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer or no elements will be read.- Returns:
- Returns
1
on success. If not enough data is available and the connection has been closed gracefully then 0 is returned. If not enough 64-bit integers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receiveArray
Reads an array of 32-bit, single-precision, floating-point numbers (i.e., floats) from the stream. This method receives an array of 32-bit, single-precision, floating-point numbers over a client stream. It differs from thereceive(float[])
method in that it treats the entire array as an atomic unit. It either receives all of the array or none of it. This method is particularly useful for non-blocking streams because it ensures that all the values requested are read at one time. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 32-bit floating-point number received or sent. Unlike thereceive(float[])
method, the size of the stream receive buffer must be at least as large as the array of 32-bit floating-point numbers being received. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer 32-bit floating-point numbers are available than the size of the entire array then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns 1. If the connection has been closed gracefully then it returns 0 only if there are fewer 32-bit floating-point numbers to receive than the size of the entire array. Otherwise it returns 1. Once there are fewer 32-bit floating-point numbers left to receive than the size of the entire array then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceiveArray
at the same time. However,sendArray
orflush()
may be called by another thread at the same time asreceiveArray
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer or no elements will be read.- Returns:
- Returns
1
on success. If not enough data is available and the connection has been closed gracefully then 0 is returned. If not enough 32-bit floating-point numbers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
receiveArray
Reads an array of 64-bit, double-precision, floating-point numbers (i.e., doubles) from the stream. This method receives an array of 64-bit, double-precision, floating-point numbers over a client stream. It differs from thereceive(double[])
method in that it treats the entire array as an atomic unit. It either receives all of the array or none of it. This method is particularly useful for non-blocking streams because it ensures that all the values requested are read at one time. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then it will swap the order of the bytes within each 64-bit floating-point number received or sent. Unlike thereceive(float[])
method, the size of the stream receive buffer must be at least as large as the array of 64-bit floating-point numbers being received. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data is read. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. If fewer 64-bit floating-point numbers are available than the size of the entire array then it returns-ErrorCode.WouldBlock
. In this case, thepoll(double, int)
method may be used with thePollFlag.receive
flag to determine when data becomes available. Otherwise it returns 1. If the connection has been closed gracefully then it returns 0 only if there are fewer 64-bit floating-point numbers to receive than the size of the entire array. Otherwise it returns 1. Once there are fewer 64-bit floating-point numbers left to receive than the size of the entire array then it will return 0 to indicate the connection has been closed. Usereceive(byte[])
to receive any remaining bytes if required. If an error occurs, then it throws aIOException
. This method does not support two threads callingreceiveArray
at the same time. However,sendArray
orflush()
may be called by another thread at the same time asreceiveArray
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer in which to store the values read. The length of this buffer determines the number of elements this method attempts to read. The number of elements read may be less than the number of elements in the buffer or no elements will be read.- Returns:
- Returns
1
on success. If not enough data is available and the connection has been closed gracefully then 0 is returned. If not enough 64-bit floating-point numbers are received and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
send
Writes the specified number of 8-bit integers (i.e., bytes) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
8-bit integers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 8-bit integers sent is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 8-bit integers sent successfully, which will be between 1 andbuffer.length
(unless thebuffer
has zero length). If no 8-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The semantics of this method are comparable to the BSDsend()
socket function. Unlike thesendArray(byte[])
method, this method does not require that the internal stream send buffer be as large as the array of 8-bit integers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.- Returns:
- The number of 8-bit integers written, which may be less than the number of elements in the
buffer
for non-blocking streams. If no 8-bit integers could be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
send
Writes the specified number of 16-bit integers (i.e., shorts) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
16-bit integers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 16-bit integer when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 16-bit integers sent is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 16-bit integers sent successfully, which will be between 1 andbuffer.length
(unless thebuffer
has zero length). If no 16-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method. Unlike thesendArray(short[])
method, this method does not require that the internal stream send buffer be as large as the array of 16-bit integers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.- Returns:
- The number of 16-bit integers written, which may be less than the number of elements in the
buffer
for non-blocking streams. If no 16-bit integers could be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
send
Writes the specified number of 32-bit integers (i.e., ints) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
32-bit integers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 32-bit integer when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 32-bit integers sent is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 32-bit integers sent successfully, which will be between 1 andbuffer.length
(unless thebuffer
has zero length). If no 32-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method. Unlike thesendArray(int[])
method, this method does not require that the internal stream send buffer be as large as the array of 32-bit integers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.- Returns:
- The number of 32-bit integers written, which may be less than the number of elements in the
buffer
for non-blocking streams. If no 32-bit integers could be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
send
Writes the specified number of 64-bit integers (i.e., longs) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
64-bit integers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 64-bit integer when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 32-bit integers sent is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 64-bit integers sent successfully, which will be between 1 andbuffer.length
(unless thebuffer
has zero length). If no 64-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method. Unlike thesendArray(long[])
method, this method does not require that the internal stream send buffer be as large as the array of 64-bit integers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.- Returns:
- The number of 64-bit integers written, which may be less than the number of elements in the
buffer
for non-blocking streams. If no 32-bit integers could be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
send
Writes the specified number of 32-bit, single-precision, floating-point (i.e., floats) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
32-bit, single-precision, floating-point numbers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 32-bit floating-point number when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 32-bit floating-point number sent is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 32-bit floating-point numbers sent successfully, which will be between 1 andbuffer.length
(unless thebuffer
has zero length). If no 32-bit floating-point numbers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method. Unlike thesendArray(float[])
method, this method does not require that the internal stream send buffer be as large as the array of 32-bit floating-point numbers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.- Returns:
- The number of 32-bit floating-point numbers written, which may be less than the number of elements in the
buffer
for non-blocking streams. If no 32-bit floating-point numbers could be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
send
Writes the specified number of 64-bit, double-precision, floating-point (i.e., doubles) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
64-bit, double-precision, floating-point numbers in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 64-bit floating-point number when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 64-bit floating-point number sent is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 64-bit floating-point numbers sent successfully, which will be between 1 andbuffer.length
(unless thebuffer
has zero length). If no 64-bit floating-point numbers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method. Unlike thesendArray(double[])
method, this method does not require that the internal stream send buffer be as large as the array of 64-bit floating-point numbers to be sent. Hence, it allows smaller stream buffers to be used. The size of the stream receive buffer is set when the stream is created using theconnect
oraccept
method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written may be less than the number of elements in the buffer, so be sure to check the return value to see how many elements were actually written.- Returns:
- The number of 64-bit floating-point numbers written, which may be less than the number of elements in the
buffer
for non-blocking streams. If no 64-bit floating-point numbers could be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendArray
Writes the specified array of 8-bit integers (i.e., bytes) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
8-bit integers in the internal stream buffer. It differs from thesend(byte[])
method in that it treats the entire array as an atomic unit. It either writes all of the array or none of it. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. This method is particularly useful for non-blocking streams because it ensures that all the values requested are written at one time. Unlike thesend(byte[])
method, the size of the stream send buffer must be at least as large as the number of 8-bit integers sent. The size of the stream send buffer is set when the stream is created using theconnect
oraccept
method. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and1
is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns1
if the entire array is sent successfully. If the entire array could not be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written is always equal to the length of this buffer if the data is sent successfully. This method never sends part of the array. It sends all of it or none of it.- Returns:
- Returns
1
on success. If the entire array could not be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendArray
Writes the specified array of 16-bit integers (i.e., shorts) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
16-bit integers in the internal stream buffer. It differs from thesend(short[])
method in that it treats the entire array as an atomic unit. It either writes all of the array or none of it. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. This method is particularly useful for non-blocking streams because it ensures that all the values requested are written at one time. Unlike thesend(short[])
method, the size of the stream send buffer must be at least as large as the number of 16-bit integers sent. The size of the stream send buffer is set when the stream is created using theconnect
oraccept
method. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and1
is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns1
if the entire array is sent successfully. If the entire array could not be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written is always equal to the length of this buffer if the data is sent successfully. This method never sends part of the array. It sends all of it or none of it.- Returns:
- Returns
1
on success. If the entire array could not be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendArray
Writes the specified array of 32-bit integers (i.e., ints) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
32-bit integers in the internal stream buffer. It differs from thesend(int[])
method in that it treats the entire array as an atomic unit. It either writes all of the array or none of it. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. This method is particularly useful for non-blocking streams because it ensures that all the values requested are written at one time. Unlike thesend(int[])
method, the size of the stream send buffer must be at least as large as the number of 32-bit integers sent. The size of the stream send buffer is set when the stream is created using theconnect
oraccept
method. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and1
is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns1
if the entire array is sent successfully. If the entire array could not be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written is always equal to the length of this buffer if the data is sent successfully. This method never sends part of the array. It sends all of it or none of it.- Returns:
- Returns
1
on success. If the entire array could not be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendArray
Writes the specified array of 64-bit integers (i.e., longs) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
64-bit integers in the internal stream buffer. It differs from thesend(long[])
method in that it treats the entire array as an atomic unit. It either writes all of the array or none of it. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. This method is particularly useful for non-blocking streams because it ensures that all the values requested are written at one time. Unlike thesend(long[])
method, the size of the stream send buffer must be at least as large as the number of 64-bit integers sent. The size of the stream send buffer is set when the stream is created using theconnect
oraccept
method. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and1
is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns1
if the entire array is sent successfully. If the entire array could not be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written is always equal to the length of this buffer if the data is sent successfully. This method never sends part of the array. It sends all of it or none of it.- Returns:
- Returns
1
on success. If the entire array could not be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendArray
Writes the specified array of 32-bit, single-precision, floating-point numbers (i.e., floats) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
32-bit, single-precision, floating-point numbers in the internal stream buffer. It differs from thesend(float[])
method in that it treats the entire array as an atomic unit. It either writes all of the array or none of it. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. This method is particularly useful for non-blocking streams because it ensures that all the values requested are written at one time. Unlike thesend(float[])
method, the size of the stream send buffer must be at least as large as the number of 32-bit floating-point numbers sent. The size of the stream send buffer is set when the stream is created using theconnect
oraccept
method. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and1
is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns1
if the entire array is sent successfully. If the entire array could not be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written is always equal to the length of this buffer if the data is sent successfully. This method never sends part of the array. It sends all of it or none of it.- Returns:
- Returns
1
on success. If the entire array could not be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendArray
Writes the specified array of 64-bit, double-precision, floating-point numbers (i.e., doubles) to the stream send buffer. This method writes data to the stream send buffer. It attempts to storebuffer.length
64-bit, double-precision, floating-point numbers in the internal stream buffer. It differs from thesend(double[])
method in that it treats the entire array as an atomic unit. It either writes all of the array or none of it. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. This method is particularly useful for non-blocking streams because it ensures that all the values requested are written at one time. Unlike thesend(double[])
method, the size of the stream send buffer must be at least as large as the number of 64-bit floating-point numbers sent. The size of the stream send buffer is set when the stream is created using theconnect
oraccept
method. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and1
is returned. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns1
if the entire array is sent successfully. If the entire array could not be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
. The BSD socket API has no equivalent to this method.- Parameters:
buffer
- The buffer containing the values to write. The length of this buffer determines the number of elements this method attempts to send. The number of elements written is always equal to the length of this buffer if the data is sent successfully. This method never sends part of the array. It sends all of it or none of it.- Returns:
- Returns
1
on success. If the entire array could not be written to the stream buffer and the method would block then-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendByte
Writes a single 8-bit integer (i.e., byte) to the stream send buffer. This method writes data to the stream send buffer. It attempts to store one 8-bit integer in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 8-bit integers sent is returned, which will be always be 1. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 8-bit integers sent successfully, which will be always be 1. If no 8-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
.- Parameters:
value
- The value to write.- Returns:
- The number of 8-bit integers written, which will always be 1.
If no 8-bit integers could be written to the stream buffer
and the method would block then
-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendShort
Writes a single 16-bit integer (i.e., short) to the stream send buffer. This method writes data to the stream send buffer. It attempts to store one 16-bit integer in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 16-bit integer when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 16-bit integers sent is returned, which will be always be 1. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 16-bit integers sent successfully, which will be always be 1. If no 8-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
.- Parameters:
value
- The value to write.- Returns:
- The number of 16-bit integers written, which will always be 1.
If no 16-bit integers could be written to the stream buffer
and the method would block then
-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendInt
Writes a single 32-bit integer (i.e., int) to the stream send buffer. This method writes data to the stream send buffer. It attempts to store one 32-bit integer in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 32-bit integer when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 32-bit integers sent is returned, which will be always be 1. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 32-bit integers sent successfully, which will be always be 1. If no 32-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
.- Parameters:
value
- The single value to write.- Returns:
- The number of 32-bit integers written, which will always be 1.
If no 32-bit integers could be written to the stream buffer
and the method would block then
-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendLong
Writes a single 64-bit integer (i.e., long) to the stream send buffer. This method writes data to the stream send buffer. It attempts to store one 64-bit integer in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 64-bit integer when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 64-bit integers sent is returned, which will be always be 1. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 32-bit integers sent successfully, which will be always be 1. If no 64-bit integers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
.- Parameters:
value
- The single value to write.- Returns:
- The number of 64-bit integers written, which will always be 1.
If no 64-bit integers could be written to the stream buffer
and the method would block then
-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendFloat
Writes a single 32-bit, single-precision, floating-point (i.e., float) to the stream send buffer. This method writes data to the stream send buffer. It attempts to store one 32-bit, single-precision, floating-point number in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 32-bit floating-point number when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 32-bit floating-point numbers sent is returned, which will be always be 1. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 32-bit floating-point numbers sent successfully, which will be always be 1. If no 32-bit floating-point numbers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
.- Parameters:
value
- The single value to write.- Returns:
- The number of 32-bit floating-point numbers written, which will always be 1.
If no 32-bit floating-point numbers could be written to the stream buffer
and the method would block then
-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
sendDouble
Writes a single 64-bit, double-precision, floating-point (i.e., double) to the stream send buffer. This method writes data to the stream send buffer. It attempts to store one 64-bit, double-precision, floating-point number in the internal stream buffer. If there is enough room available in the stream buffer then it stores the data in the buffer and returns immediately. The data is not written to the actual communication channel until the stream is flushed usingflush()
or there is no more room available in the stream buffer. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. If the stream has been configured to swap bytes using thesetSwapBytes(boolean)
method then this function will swap the order of the bytes within each 64-bit floating-point number when they are sent. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method may block attempting to flush the stream buffer. All the data will be consumed and the total number of 64-bit floating-point numbers sent is returned, which will be always be 1. Some of the data may remain in the stream buffer and not be sent until the next timeflush()
is called or there is no more room available in the stream buffer. If an error occurs then the aIOException
is thrown and the stream should be closed. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It returns the number of 64-bit floating-point numbers sent successfully, which will be always be 1. If no 64-bit floating-point numbers could be sent without blocking, then-ErrorCode.WouldBlock
is returned. In this case, thepoll(double, int)
method may be used with thePollFlag.send
flag to determine when space in the buffer becomes available. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush()
at the same time. However,receive
may be called by another thread at the same time assend
.- Parameters:
value
- The single value to write.- Returns:
- The number of 64-bit floating-point numbers written, which will always be 1.
If no 64-bit floating-point numbers could be written to the stream buffer
and the method would block then
-ErrorCode.WouldBlock
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
flush
Flushes the stream send buffer to the underlying communication channel. This method flushes the stream buffer. It attempts to send the contents of the buffer over the communication channel, even if the buffer is not full. If an error occurs, then it throws aIOException
. If the connection is closed it is considered an error condition. Iflisten
orconnect
was called with the non-blocking flag set tofalse
, then this method blocks until all the data in the buffer is sent. Iflisten
orconnect
was called with the non-blocking flag set totrue
, then this method does not block. It attempts to send all the data remaining in the stream buffer. However, if this operation would block then it returnsfalse
, even if it has already sent some of the data. In this case, thepoll(double, int)
method may be used with thePollFlag.flush
flag to determine when at least one more byte may be flushed. If an error occurs then aIOException
is thrown and the stream should be closed. This method does not support two threads callingsend
orflush
at the same time. However,receive
may be called by another thread at the same time asflush
.- Returns:
- Returns
true
if all the data in the buffer is flushed successfully. If some of the data could not be sent over the underlying communication channel, thenfalse
is returned for non-blocking streams. If an error occurs then aIOException
is thrown. - Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if an error has occurred in the underlying communication channel, such as the connection being lost unexpectedly.
-
shutdown
Shuts down send and/or receive operations in preparation for closing the stream. It is typically called from another thread in order to interrupt a blocking send or receive operation prior to closing the stream. If an error occurs, then it throwsIOException
. If the connection is closed it is considered an error condition.- Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if the stream was closed prior to callingshutdown()
.
-
close
Closes the stream. This method closes the stream. All resources associated with the stream are freed. If an error occurs, then it throwsIOException
. If the connection is already closed it is considered an error condition.- Throws:
IOException
- If an error occurs then an exception is thrown. This situation typically arises if the stream was already closed prior to callingclose
.
-
closeAll
Closes all streams currently connected or listening. This method closes all streams that are currently connected or listening. All resources associated with those streams are freed. This method is typically used in exceptional conditions in order to ensure that all streams are closed. Note that only those streams that are associated with the current process are closed.- Throws:
IOException
- If an error occurs then an exception is thrown.
-