Skip to Main Content

Java Security

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Getting SocketTimeoutException in DatagramPacket.receive in centOS8

3155849Jun 11 2020 — edited Jun 11 2020

Hi,

To understand this issue , wrote simple socket program with DatagramPacket.receive method.

Program works fine in centOS7 but it is not working in centOS8.

Let me know if the issue specfic to centOS8?

Program snip:

int transId = sequence.incrementAndGet();

try{

ByteBuffer getBuffer = ByteBuffer.allocate(DATAGRAM_LENGTH);

byte transByte1 = (byte) (transId & 0xFF);

byte transByte2 = (byte) ((transId >> 8) & 0xFF);

buildHeader(getBuffer, transByte1, transByte2);

String getBuf = "stats\r\n";

getBuffer.put(getBuf.getBytes());

DatagramPacket getPacket = new DatagramPacket(getBuffer.array(),getBuffer.position());

getPacket.setSocketAddress(sa);

DatagramSocket socket = channel.get().socket();

socket.send(getPacket);

DatagramPacket getResult = new DatagramPacket(new byte[DATAGRAM_LENGTH], DATAGRAM_LENGTH);

socket.setSoTimeout(MEMCACHE_MONITOR_TIMEOUT);

socket.receive(getResult);

byte[] data = getResult.getData();

if(data != null){

return true;

}

}

catch (SocketTimeoutException so)

{

try {

channel.get().close();

DatagramChannel newChannel = DatagramChannel.open();

newChannel.configureBlocking(true);

channel.set(newChannel);

} catch (IOException e) {

}

System.out.println("Get Stats from socket timed out");

return false;

}

Thanks

Comments
Post Details
Added on Jun 11 2020
0 comments
103 views