1
votes

I'm trying to make a basic datagram client/server program with Java.

I've made the server cling to port 9321 on my local computer.

I've made the client on port 9320 on my local computer, then send the data over wireless router network (192.168.1.100) at port 9321 the program works!

then i try to send the packet over (via router)internet IP 139.195.12.183(my ip) at port 9321 but it didnt work! there is this exception:

java.net.SocketException: Interrupted function call: Datagram send failed

i've set the router to forward any request for port 9321 to my computer and then i've set exception for the firewall on my computer on that port

this is the source

String SERVER = "139.195.12.183";

sendString(SERVER, 9321, "Greetings"); <<


private void sendString(String IP, int port, String toSend) {
    byte[] buf = toSend.getBytes();
    DatagramPacket packet = null;
    try {

        packet = new DatagramPacket(buf, buf.length, InetAddress.getByName(SERVER), port);

        ds.send(packet);<<
    }catch(UnknownHostException e) {
        System.out.println("unknownhostception");
    }catch(IOException e) {
        System.err.println("ioception "+e.getMessage());

    }

}

i've had another answers from another forum it said:

"The way routers work, you can't see your external (WAN) internet address from your internal network (LAN). If that's what you are trying to do, there's nothing wrong, it just won't work.

Ian."

any explanation?

1
Just to clarify - global network == internet? Your local PC does have a publicly available IP address (the IP you mentioned belongs to a carrier)?home
ah yes i mean internet. the private network is my router.Keenan Gebze
If you use IP datagram, always think about its TTL.ecle
Can't see anything wrong with the code. I'd grab wireshark to have a look at what's being sent.brice
@brice i've install wireshark, the packet is not even being sent (there is no packet)Keenan Gebze

1 Answers

0
votes

Some steps that you can take:

  1. Check that the code works across two machines on your LAN.
  2. Check that ping <target-ip> works on your machine.
  3. If it does, check your local and LAN firewall settings for blocking on the port/protocol.
  4. If the ports are unblocked change the port to something else. Some ISPs will block certain ports.

Some more reasons why this error could come up:

  • UDP (I Assume?) datagram too large.
  • Client side error that doesn't affect reception (Have seen similar things with some network stacks where the error was spurious.)

Post a link to your code from patsebin or something if you want more info.