BAEL-4786 - review comments - removed close method
This commit is contained in:
parent
16d345ea1b
commit
d7577d2601
@ -17,7 +17,6 @@ public class DatagramClient {
|
|||||||
public static void sendMessage(DatagramChannel client, String msg, SocketAddress serverAddress) throws IOException {
|
public static void sendMessage(DatagramChannel client, String msg, SocketAddress serverAddress) throws IOException {
|
||||||
ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
|
ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
|
||||||
client.send(buffer, serverAddress);
|
client.send(buffer, serverAddress);
|
||||||
client.close();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public static void main(String[] args) throws IOException {
|
public static void main(String[] args) throws IOException {
|
||||||
|
@ -24,8 +24,6 @@ public class DatagramServer {
|
|||||||
|
|
||||||
System.out.println("Client at #" + remoteAdd + " sent: " + message);
|
System.out.println("Client at #" + remoteAdd + " sent: " + message);
|
||||||
|
|
||||||
server.close();
|
|
||||||
|
|
||||||
return message;
|
return message;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -12,13 +12,18 @@ public class DatagramChannelUnitTest {
|
|||||||
@Test
|
@Test
|
||||||
public void whenClientSendsAndServerReceivesUDPPacket_thenCorrect() throws IOException {
|
public void whenClientSendsAndServerReceivesUDPPacket_thenCorrect() throws IOException {
|
||||||
DatagramChannel server = DatagramServer.startServer();
|
DatagramChannel server = DatagramServer.startServer();
|
||||||
|
|
||||||
DatagramChannel client = DatagramClient.startClient();
|
DatagramChannel client = DatagramClient.startClient();
|
||||||
String msg = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
|
|
||||||
|
String msg1 = "Hello, this is a Baeldung's DatagramChannel based UDP client!";
|
||||||
|
String msg2 = "Hi again!, Are you there!";
|
||||||
|
|
||||||
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
|
InetSocketAddress serverAddress = new InetSocketAddress("localhost", 7001);
|
||||||
DatagramClient.sendMessage(client, msg, serverAddress);
|
|
||||||
|
DatagramClient.sendMessage(client, msg1, serverAddress);
|
||||||
|
DatagramClient.sendMessage(client, msg2, serverAddress);
|
||||||
|
|
||||||
assertEquals("Hello, this is a Baeldung's DatagramChannel based UDP client!", DatagramServer.receiveMessage(server));
|
assertEquals("Hello, this is a Baeldung's DatagramChannel based UDP client!", DatagramServer.receiveMessage(server));
|
||||||
|
assertEquals("Hi again!, Are you there!", DatagramServer.receiveMessage(server));
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user