Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

My code can't receive UDP messages from outside my home net. The communication is between Android and Java computer application, with IP inside my LAN (for example 192.168.0.3) the code works, if I put my Java computer application inside my online server (and obviously I changed every IP with external IPs) this doesn't work; Android can send but it can't receive.

Android code :

@Override
protected Integer doInBackground(Void... params) {
    DatagramSocket socket = null;
    byte[] buf = new byte[1024];
    DatagramPacket packet = new DatagramPacket(buf, buf.length);
    try {
        socket = new DatagramSocket(25565);
    } catch (Exception e) {
        Log.i("Ex ", "");
    }
    while (true) {
        try {
            socket.receive(packet);
            String message = new String(packet.getData(), 0,packet.getLength());
            Log.i("message", "" + message);
        } catch (IOException e) {
            Log.i("IO Ex", "");
        }
        catch (Exception e){
        }
    }
}

Java computer application code : http://pastebin.com/2hVGeP6R

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
238 views
Welcome To Ask or Share your Answers For Others

1 Answer

192.168.0.X is an internal NAT address. Any network can use it, but it can't be reached from anywhere outside. You either need to configure your router to pass it through to your PC and hit the router's external IP, or you need a real network address.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...