Java socket API: How to tell if a connection has been closed?

There is no TCP API that will tell you the current state of the connection. isConnected() and isClosed() tell you the current state of your socket. Not the same thing. isConnected() tells you whether you have connected this socket. You have, so it returns true. isClosed() tells you whether you have closed this socket. Until … Read more

Regular expression that matches valid IPv6 addresses

I was unable to get @Factor Mystic’s answer to work with POSIX regular expressions, so I wrote one that works with POSIX regular expressions and PERL regular expressions. It should match: IPv6 addresses zero compressed IPv6 addresses (section 2.2 of rfc5952) link-local IPv6 addresses with zone index (section 11 of rfc4007) IPv4-Embedded IPv6 Address (section … Read more

How do I check for a network connection?

The marked answer is 100% fine, however, there are certain cases when the standard method is fooled by virtual cards (virtual box, …). It’s also often desirable to discard some network interfaces based on their speed (serial ports, modems, …). Here is a piece of code that checks for these cases: /// <summary> /// Indicates … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)