public class UnetSocket extends java.lang.Object
Unet socket for transmission/reception of datagrams. This class is not thread-safe.
| Modifiers | Name | Description |
|---|---|---|
static int |
BLOCKING |
When used as a timeout value, indicates a blocking receive(). |
static int |
NON_BLOCKING |
When used as a timeout value, indicates a non-blocking receive(). |
protected static long |
REQUEST_TIMEOUT |
|
static int |
SEMI_BLOCKING |
When used as a send mode, indicates semi-blocking send(). |
protected org.arl.fjage.remote.Gateway |
gw |
|
protected int |
localProtocol |
|
protected java.lang.String |
mailbox |
|
protected java.lang.String |
messageClass |
|
protected java.lang.String |
mimeType |
|
protected Priority |
priority |
|
protected org.arl.fjage.AgentID |
provider |
|
protected java.lang.Boolean |
reliability |
|
protected int |
remoteAddress |
|
protected int |
remoteProtocol |
|
protected java.lang.String |
remoteRecipient |
|
protected Robustness |
robustness |
|
protected java.lang.String |
route |
|
protected int |
sendMode |
|
protected long |
timeout |
|
protected float |
ttl |
|
protected java.lang.Thread |
waiting |
| Type | Name and description |
|---|---|
java.lang.String |
messageClass |
java.lang.String |
mimeType |
Priority |
priority |
java.lang.Boolean |
reliability |
java.lang.String |
remoteRecipient |
Robustness |
robustness |
java.lang.String |
route |
int |
sendMode |
org.arl.fjage.AgentID |
serviceProvider |
long |
timeout |
float |
ttl |
| Constructor and description |
|---|
UnetSocket
(org.arl.fjage.Container container)Creates a socket running in a container. |
UnetSocket
(java.lang.String hostname, int port)Creates a socket connected to a master container over TCP/IP. |
UnetSocket
(java.lang.String devname, int baud, java.lang.String settings)Creates a socket connected to a master container over RS232. |
UnetSocket
(org.arl.fjage.shell.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 |
|---|---|---|
|
org.arl.fjage.AgentID |
agent(java.lang.String name)Gets a named AgentID for low-level access to UnetStack. |
|
org.arl.fjage.AgentID |
agentForService(java.lang.String svc)Gets an AgentID providing a specified service for low-level access to UnetStack. |
|
org.arl.fjage.AgentID |
agentForService(java.lang.Enum<?> svc)Gets an AgentID providing a specified service for low-level access to UnetStack. |
|
org.arl.fjage.AgentID[] |
agentsForService(java.lang.String svc)Gets a list of AgentIDs providing a specified service for low-level access to UnetStack. |
|
org.arl.fjage.AgentID[] |
agentsForService(java.lang.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. |
|
protected DatagramReq |
createDatagramReq() |
|
void |
disconnect()Resets the default destination address to undefined, and the default protocol number to Protocol.DATA. |
|
org.arl.fjage.remote.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. |
|
java.lang.String |
getMessageClass()Gets the message class for transmitted datagrams. |
|
java.lang.String |
getMimeType()Gets the MIME type for transmitted datagrams. |
|
Priority |
getPriority()Gets the priority for transmitted datagrams. |
|
java.lang.Boolean |
getReliability()Gets the reliability for transmitted datagrams. |
|
int |
getRemoteAddress()Gets the default destination node address for a connected socket. |
|
int |
getRemoteProtocol()Gets the default transmission protocol number. |
|
java.lang.String |
getRemoteRecipient()Gets the remote recipient for transmitted datagrams. |
|
Robustness |
getRobustness()Gets the robustness for transmitted datagrams. |
|
java.lang.String |
getRoute()Gets the route ID for transmitted datagrams. |
|
int |
getSendMode()Gets the send mode for datagram transmission. |
|
org.arl.fjage.AgentID |
getServiceProvider()Get service provider AgentID. |
|
long |
getTimeout()Gets the timeout for datagram reception. |
|
float |
getTtl()Gets the time-to-live (TTL) for transmitted datagrams. |
|
java.lang.Integer |
host(java.lang.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. |
|
protected boolean |
send(DatagramReq req) |
|
void |
setMessageClass(java.lang.String messageClass)Sets the message class for transmitted datagrams. |
|
void |
setMimeType(java.lang.String mimeType)Sets the MIME type for transmitted datagrams. |
|
void |
setPriority(Priority priority)Sets the priority for transmitted datagrams. |
|
void |
setReliability(java.lang.Boolean reliability)Sets the reliability for transmitted datagrams. |
|
void |
setRemoteRecipient(java.lang.String remoteRecipient)Sets the remote recipient for transmitted datagrams. |
|
void |
setRobustness(Robustness robustness)Sets the robustness for transmitted datagrams. |
|
void |
setRoute(java.lang.String route)Sets the route ID for transmitted datagrams. |
|
void |
setSendMode(int mode)Sets the send mode for datagram transmission. |
|
void |
setServiceProvider(org.arl.fjage.AgentID provider)Sets service provider AgentID. |
|
void |
setTimeout(long ms)Sets the timeout for datagram reception. |
|
void |
setTtl(float ttl)Sets the time-to-live (TTL) for transmitted datagrams. |
|
void |
unbind()Unbinds a socket so that it listens to all unreserved protocols. |
| Methods inherited from class | Name |
|---|---|
class java.lang.Object |
java.lang.Object#wait(long, int), java.lang.Object#wait(long), java.lang.Object#wait(), java.lang.Object#equals(java.lang.Object), java.lang.Object#toString(), java.lang.Object#hashCode(), java.lang.Object#getClass(), java.lang.Object#notify(), java.lang.Object#notifyAll() |
When used as a timeout value, indicates a blocking receive(). The receive() call blocks indefinitely until data is available.
When used as a send mode, indicates blocking send(). Waits until the data is transmitted. If the socket is reliable, waits until delivery is acknowledged or fails.
When used as a timeout value, indicates a non-blocking receive(). If data is available, it is returned immediately, otherwise returns null.
When used as a send mode, indicates non-blocking send(). Makes a request to send data, but does not wait for acceptance or transmission.
When used as a send mode, indicates semi-blocking send(). Waits until the data is accepted for transmission, but does not wait for actual transmission for unreliable sockets. If the socket is reliable, waits until delivery is acknowledged or fails.
Not a valid timeout value for receive().
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 message class for transmitted datagrams.
Gets the MIME type for transmitted datagrams.
Gets the priority for transmitted datagrams.
Gets the reliability for transmitted datagrams.
Gets the default destination node address for a connected socket.
Gets the default transmission protocol number.
Gets the remote recipient for transmitted datagrams.
Gets the robustness for transmitted datagrams.
Gets the route ID for transmitted datagrams.
Gets the send mode for datagram transmission.
Get service provider AgentID.
Gets the timeout for datagram reception.
Gets the time-to-live (TTL) for transmitted datagrams.
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 available, 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 numberSets the message class for transmitted datagrams.
messageClass - message class (null to unset)Sets the MIME type for transmitted datagrams.
mimeType - MIME type (null to unset)Sets the priority for transmitted datagrams.
priority - prioritySets the reliability for transmitted datagrams.
reliability - true for reliable, false for unreliable, null to unsetSets the remote recipient for transmitted datagrams.
remoteRecipient - remote recipient (null to unset)Sets the robustness for transmitted datagrams.
robustness - robustnessSets the route ID for transmitted datagrams.
route - route ID (null to unset)Sets the send mode for datagram transmission.
NON_BLOCKING mode makes a request to send data, but does not wait for acceptance or transmission. BLOCKING mode waits until the data is transmitted. If the socket is reliable, waits until delivery is acknowledged or fails. SEMI_BLOCKING mode waits until the data is accepted for transmission, but does not wait for actual transmission for unreliable sockets.
mode - send mode (0 for NON_BLOCKING, -1 for BLOCKING, or -2 for SEMI_BLOCKING)Sets service provider AgentID.
provider - service provider AgentIDSets the timeout for datagram reception. The default timeout is infinite (BLOCKING), i.e., the receive() call blocks forever. A timeout of 0 (NON_BLOCKING) means the receive() call is non-blocking.
ms - timeout in milliseconds, or -1 (BLOCKING) for infinite timeoutSets the time-to-live (TTL) for transmitted datagrams.
ttl - time-to-live in seconds (Float.NaN to unset)Unbinds a socket so that it listens to all unreserved protocols.
Protocol numbers between Protocol.DATA+1 to Protocol.USER-1 are considered reserved.
Groovy Documentation