Fixes issue #507 Correctly support ipv6 sockets

This fixes issues support ipv6 sockets