Fix socket2

I think this solutions is the best fix for issue #245

taken from udp2.c in libnet samples.