Based on the premise that UDP is a connectionless protocol I had presumed that whether a host is up or down would be irrelevant.
However, now that I'm doing testing I've discovered that when I have "connected" my UDP client socket, a write
to that socket returns an error because the server has sent back a ICMP Port Unreachable error ..
The purpose of "connecting" the UDP port (According to Stevens Unix Network Programming) is to basically caches the entry from the routing table, rather than creating a new one for each packet, which is supposed to have performance benefits.
However, this ICMP packet is causing me to lose my client socket, which is very annoying.
Can anybody shed any light on why this could be? Are there any known workarounds?
I'm using a 3p java library that doesn't account for this and just disconnects and I'll probably have to hack it to reconnect, but before I do I was kind of hoping there was something I could do at the (Linux) operating system level maybe to prevent this happening ... all investigations into socket options etc. have turned out to be unfruitful.
EDIT
In summary this isn't possible and fixing the code is the only way to do this.
The only possibility appears to be configuring iptables to block the ICMP responses but that's a bit of a sledgehammer to crack this particular nut.
write
to it? – AlnitakUDPAppender
in log4j, which uses connected sockets, but provides no means for recovery if the far end disappears. bz.apache.org/bugzilla/show_bug.cgi?id=57891 – Alnitakaddress
field could be used for, it just seems that the BSD folks decided not to fill it in if there's an ICMP error. WRS is no longer with us, but I know one of the co-authors and could ask him about it. – Alnitak