Modifiers | Name | Description |
---|---|---|
protected static int |
BLOCKING |
|
protected static int |
NON_BLOCKING |
|
protected static long |
REQUEST_TIMEOUT |
|
protected Gateway |
gw |
|
protected int |
localProtocol |
|
protected AgentID |
provider |
|
protected int |
remoteAddress |
|
protected int |
remoteProtocol |
|
protected long |
timeout |
|
protected Thread |
waiting |
Type | Name and description |
---|---|
long |
timeout |
Constructor and description |
---|
UnetSocket
(Container container) Creates a socket running in a container. |
UnetSocket
(String hostname, int port) Creates a socket connected to a master container over TCP/IP. |
UnetSocket
(String devname, int baud, String settings) Creates a socket connected to a master container over RS232. |
UnetSocket
(BaseGroovyScript script) Creates a socket connected to a local container running the shell from which the base script runs. |
Type Params | Return Type | Name and description |
---|---|---|
|
AgentID |
agent(String name) Gets a named AgentID for low-level access to UnetStack. |
|
AgentID |
agentForService(String svc) Gets an AgentID providing a specified service for low-level access to UnetStack. |
|
AgentID |
agentForService(Enum<?> svc) Gets an AgentID providing a specified service for low-level access to UnetStack. |
|
AgentID[] |
agentsForService(String svc) Gets a list of AgentIDs providing a specified service for low-level access to UnetStack. |
|
AgentID[] |
agentsForService(Enum<?> svc) Gets a list of AgentIDs providing a specified service for low-level access to UnetStack. |
|
boolean |
bind(int protocol) Binds a socket to listen to a specific protocol datagrams. |
|
void |
cancel() Cancels an ongoing blocking receive(). |
|
void |
close() Closes the socket. |
|
boolean |
connect(int to, int protocol) Sets the default destination address and destination protocol number for datagrams sent using this socket. |
|
void |
disconnect() Resets the default destination address to undefined, and the default protocol number to Protocol.DATA. |
|
Gateway |
getGateway() Gets a Gateway to provide low-level access to UnetStack. |
|
int |
getLocalAddress() Gets the local node address. |
|
int |
getLocalProtocol() Gets the protocol number that the socket is bound to. |
|
int |
getRemoteAddress() Gets the default destination node address for a connected socket. |
|
int |
getRemoteProtocol() Gets the default transmission protocol number. |
|
long |
getTimeout() Gets the timeout for datagram reception. |
|
Integer |
host(String nodeName) Resolve node name to node address. |
|
protected void |
init() |
|
boolean |
isBound() Checks if a socket is bound. |
|
boolean |
isClosed() Checks if a socket is closed. |
|
boolean |
isConnected() Checks if a socket is connected, i.e., has a default destination address and protocol number. |
|
DatagramNtf |
receive() Receives a datagram sent to the local node and the bound protocol number. |
|
boolean |
send(byte[] data) Transmits a datagram to the default node address using the default protocol. |
|
boolean |
send(byte[] data, int to) Transmits a datagram to the specified node address using the default protocol. |
|
boolean |
send(byte[] data, int to, int protocol) Transmits a datagram to the specified node address using the specified protocol. |
|
boolean |
send(DatagramReq req) Transmits a datagram to the specified node address using the specified protocol. |
|
void |
setTimeout(long ms) Sets the timeout for datagram reception. |
|
void |
unbind() Unbinds a socket so that it listens to all unreserved protocols. |
Creates a socket running in a container.
container
- containerCreates a socket connected to a master container over TCP/IP.
hostname
- host name or IP address of master containerport
- TCP port number for master containerCreates a socket connected to a master container over RS232.
devname
- RS232 device namebaud
- RS232 baud ratesettings
- RS232 settings string (e.g. "N81")Creates a socket connected to a local container running the shell from which the base script runs. This is useful in a shell script to invoke as:
sock = new org.arl.unet.api.UnetSocket(this)
script
- Groovy script object connected with the local containerGets a named AgentID for low-level access to UnetStack.
name
- name of the agentGets an AgentID providing a specified service for low-level access to UnetStack.
svc
- name of the serviceGets an AgentID providing a specified service for low-level access to UnetStack.
svc
- name of the serviceGets a list of AgentIDs providing a specified service for low-level access to UnetStack.
svc
- name of the serviceGets a list of AgentIDs providing a specified service for low-level access to UnetStack.
svc
- name of the serviceBinds a socket to listen to a specific protocol datagrams.
Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are reserved protocols and cannot be bound. Unbound sockets listen to all unreserved protocols.
protocol
- protocol number to listen forCancels an ongoing blocking receive().
Closes the socket. The socket functionality may not longer be accessed after this method is called.
Sets the default destination address and destination protocol number for datagrams sent using this socket. The defaults can be overridden for specific send() calls.
The default protocol number when a socket is opened is Protocol.DATA. The default node address is undefined. Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved, and cannot be used for sending datagrams using the socket.
to
- default destination node addressprotocol
- default protocol numberResets the default destination address to undefined, and the default protocol number to Protocol.DATA.
Gets a Gateway to provide low-level access to UnetStack.
Gets the local node address.
Gets the protocol number that the socket is bound to.
Gets the default destination node address for a connected socket.
Gets the default transmission protocol number.
Gets the timeout for datagram reception.
Resolve node name to node address.
nodeName
- name of node to resolveChecks if a socket is bound.
Checks if a socket is closed.
Checks if a socket is connected, i.e., has a default destination address and protocol number.
Receives a datagram sent to the local node and the bound protocol number. If the socket is unbound, then datagrams with all unreserved protocols are received. Any broadcast datagrams are also received.
This call blocks until a datagram is availbale, the socket timeout is reached, or until cancel() is called.
Transmits a datagram to the default node address using the default protocol.
data
- bytes to transmitTransmits a datagram to the specified node address using the default protocol.
data
- bytes to transmitto
- destination node addressTransmits a datagram to the specified node address using the specified protocol.
Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved, and cannot be used for sending datagrams using the socket.
data
- bytes to transmitto
- destination node addressprotocol
- protocol numberTransmits a datagram to the specified node address using the specified protocol.
Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved, and cannot be used for sending datagrams using the socket.
req
- datagram transmission requestSets the timeout for datagram reception. The default timeout is infinite, i.e., the receive() call blocks forever. A timeout of 0 means the receive() call is non-blocking.
ms
- timeout in milliseconds, or -1 for infinite timeoutUnbinds a socket so that it listens to all unreserved protocols.
Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved.
Copyright 2013-21, Acoustic Research Laboratory, National University of Singapore, and Subnero Pte Ltd