0

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

nixgadget
  • 6,983
  • 16
  • 70
  • 103
  • I think it's the XP behavior that's odd - you don't need to be connected to send a UDP datagram. – sje397 Sep 15 '10 at 06:03
  • windows xp throws an exception when this happens however windows 7 doesnt .... this is basically my question. if it does throw an error then it allows me to establish a connection. – nixgadget Sep 15 '10 at 06:21

1 Answers1

0

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.

nixgadget
  • 6,983
  • 16
  • 70
  • 103