java.lang.Object
net.i2p.sam.SAMv3DatagramServer
- All Implemented Interfaces:
Handler
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate classThread reading the datagrams from the clients.private static classThread handling one received datagram.Field Summary
FieldsModifier and TypeFieldDescriptionprivate final StringThe host the socket is bound to.private final ThreadThread reading from the socket.private final SAMBridgeThe bridge serving the destination.private final intThe port the socket is bound to.private final DatagramChannelThe UDP socket the clients connect to.Constructor Summary
ConstructorsConstructorDescriptionSAMv3DatagramServer(SAMBridge parent, String host, int port, Properties props) Does not start listener.Method Summary
All MethodsModifier and TypeMethodDescriptiongetHost()The host this server listens on, as passed to the constructor and registered with the port mapper so clients can find it.intgetPort()The port this server listens on, as passed to the constructor and registered with the port mapper so clients can find it.voidsend(SocketAddress addr, ByteBuffer msg) Writes one datagram to the channel at the given address.voidstart()Only call once.voidCannot be restarted.
Field Details
_server
The UDP socket the clients connect to._listener
Thread reading from the socket._parent
The bridge serving the destination._host
The host the socket is bound to._port
private final int _portThe port the socket is bound to.
Constructor Details
SAMv3DatagramServer
public SAMv3DatagramServer(SAMBridge parent, String host, int port, Properties props) throws IOException Does not start listener. Caller must callstart().- Parameters:
parent- may be nullhost- the local address to bind the datagram channel toport- the local port to bind, 0 to let the system chooseprops- configuration properties (reserved for future use)- Throws:
IOException- if the channel cannot be opened or the local address cannot be bound
Method Details
start
public void start()Only call once.stopHandling
send
Writes one datagram to the channel at the given address.- Parameters:
addr- the destination to deliver the datagram tomsg- the datagram to send, positioned at its first byte and consumed by this call- Throws:
IOException- if the datagram cannot be written to the channel
getHost
The host this server listens on, as passed to the constructor and registered with the port mapper so clients can find it.- Returns:
- the local host address this server was bound to
getPort
public int getPort()The port this server listens on, as passed to the constructor and registered with the port mapper so clients can find it.- Returns:
- the local port this server was bound to