I am trying to get data from a UDP server. I have made the client udp socket for receiving data from UDP-server. Perfectly getting data in wire-shark but the udp.receive(package) is not getting data.
I have already tried the different ips like 192.168.0.252 is the source in the wire shark and my local IP(127.0.0.1). I have also tried without interface.
NetworkInterface nif = NetworkInterface.getByName("enp2s0");
if(nif==null){
System.err.println("Error getting the Network Interface");
return;
}
System.out.println("Preparing to using the interface: "+nif.getName());
Enumeration<InetAddress> nifAddresses = nif.getInetAddresses();
InetSocketAddress inetAddr= new InetSocketAddress("127.0.0.1",6723);
//socket.bind(new InetSocketAddress(nifAddresses.nextElement(), 0));
this.udpSocket = new DatagramSocket(inetAddr);
System.out.println("Interface setted");
//Till this code is initialised perfectly
byte[] buf = new byte[1024];
DatagramPacket packet = new DatagramPacket(buf, buf.length);
// blocks until a packet is received
udpSocket.receive(packet);
//Data stucking here
msg = new String(packet.getData()).trim();
System.out.println(
"Message from " + packet.getAddress().getHostAddress() + ": " + msg);
The code remain in running mode but not receiving data