BAEL-4786 - review comments - removed close method

This commit is contained in:
Anshul BANSAL 2021-04-07 13:20:24 +03:00
parent 16d345ea1b
commit d7577d2601
3 changed files with 8 additions and 6 deletions

View File

@ -17,7 +17,6 @@ public class DatagramClient {
public static void sendMessage(DatagramChannel client, String msg, SocketAddress serverAddress) throws IOException {
ByteBuffer buffer = ByteBuffer.wrap(msg.getBytes());
client.send(buffer, serverAddress);
client.close();
}
public static void main(String[] args) throws IOException {

View File

@ -24,8 +24,6 @@ public class DatagramServer {
System.out.println("Client at #" + remoteAdd + " sent: " + message);
server.close();
return message;
}

View File

@ -12,13 +12,18 @@ public class DatagramChannelUnitTest {
@Test
public void whenClientSendsAndServerReceivesUDPPacket_thenCorrect() throws IOException {
DatagramChannel server = DatagramServer.startServer();
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);
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("Hi again!, Are you there!", DatagramServer.receiveMessage(server));
}
}