Constructor and Description |
---|
UdpSocket(int port)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
close()
Close the socket.
|
InetAddress |
getAddress()
Return our own SocketAddress.
|
DatagramChannel |
getChannel()
Return the UDP channel.
|
String |
getFrom()
Return the IP address of peer that sent last message.
|
String |
getHost()
Return our own IP address as printable string.
|
int |
getPort()
Return the UDP socket port.
|
SocketAddress |
getSender()
Return the SocketAddress of the peer that sent last message.
|
DatagramSocket |
getSocket()
Return the UDP socket.
|
int |
receive(ByteBuffer buffer)
Receive a message from UDP broadcast.
|
void |
send(ByteBuffer buffer)
Send a message using UDP broadcast.
|
void |
send(ByteBuffer buffer,
String address)
Send a message using UDP.
|
public UdpSocket(int port) throws IOException
port
- The local port to bind toIOException
- If an I/O error occurs opening the socket connectionpublic void close()
public DatagramChannel getChannel()
public DatagramSocket getSocket()
public InetAddress getAddress()
public String getHost()
public int getPort()
public SocketAddress getSender()
public String getFrom()
public void send(ByteBuffer buffer) throws IOException
buffer
- The message as a byte bufferIOException
- If an error occurs sending the messagepublic void send(ByteBuffer buffer, String address) throws IOException
buffer
- The message as a byte bufferaddress
- The host name or address of the serverIOException
- If an error occurs sending the messagepublic int receive(ByteBuffer buffer) throws IOException
buffer
- The buffer to place received data intoIOException
- If an error occurs receiving the messageCopyright © 2019. All rights reserved.