hello everyone, I'd like to ask why is this error occurs.
I am trying to get a string data from a device which is connected via WiFi. I have make this code and it runs well when I try to obtain data from a local server (by LAN), but it stated this error when it connects to the device.
java.net.PortUnreachableException: ICMP Port Unreachable at java.net.DualStackPlainDatagramSocketImpl.socketReceiveOrPeekData(Native Method) at java.net.DualStackPlainDatagramSocketImpl.receive0(DualStackPlainDatagramSocketImpl.java:105) at java.net.AbstractPlainDatagramSocketImpl.receive(AbstractPlainDatagramSocketImpl.java:145) at java.net.DatagramSocket.receive(DatagramSocket.java:786) at udp_test.main(udp_test.java:28)
here is my codethe address in this code is the address of my device.public class udp_test { public static void main(String[] args) throws IOException { InetAddress IP = InetAddress.getByName("192.168.1.2"); int port = 5554; //try 5555 or 5554 or 5551 while (true) { try { byte [] datapacket = new byte [128]; DatagramSocket ds = new DatagramSocket(); DatagramPacket dp = new DatagramPacket(datapacket, datapacket.length); ds.setSoTimeout(100); ds.connect(IP, port); ds.send(dp); ds.isConnected(); ds.receive(dp); ds.close(); String strRecv = new String(dp.getData(), 0, dp.getLength()) + " from " + dp.getAddress().getHostAddress() + " port " + dp.getPort(); System.out.println(strRecv); try { Thread.sleep(1000); } catch (InterruptedException e) { // TODO Auto-generated catch block e.printStackTrace(); } } catch (SocketException e) { // TODO Auto-generated catch block e.printStackTrace(); } } } }
it's simply change the IP address, byte size and port when I connect to my device or should I change something else?
thanks before