Java DatagramSocket on Windows 7

Guys im having some trouble with some inconsistency of running a piece of code on Windows XP and Windows 7.

Basically im trying to send a UDP packet by doing,

DatagramSocket sendSocket = new DatagramSocket();
DatagramPacket dummyPacket = new DatagramPacket(new byte[ 1 ], 1,
            configuration.remoteAddress, DUMMY_PORT);
try {
    sendSocket.send(dummyPacket);
    log("send dummy packet succeeded so assume already connected");
} catch (NoRouteToHostException nrthe) {
    log("alreadyConnected: no route to host so assume not connected");
} catch (Exception e) {
    errorHandler.handleException("send dummy packet failed", e, ErrorAndWarningHandler.ERROR);
}

On Windows 7 I’m always getting success whether I connect to the remote host or not. Where as on Windows XP I’m getting an exception which is what I am expecting. Can someone tell me what I am doing wrong here for it to not work on Windows 7 ????

Appreciate it

Answer

This appears to be some sort of discrepancy on Windows 7 and Windows XP. As sje397 it could be the behavior on XP that is wrong. I confirmed the behavior by writing a small VB application to write to the UDP socket. XP doesnt allow it but Windows 7 does. Ohh well guess I will have to find an alternative solution like may be pinging an ip or something to check the connection is alive.

Leave a Reply

Your email address will not be published. Required fields are marked *