I tested the snip with the same Java code, in BCM943362WCD4. When I ran the code from Mac OS, it almost never connects to device. I then tried a python script on Windows, this time it connects most of the time but I still see error 7014 around %5 of trials. Also when I get error 7014, I cannot connect to socket again whatever I do(I even tried memsetting socket to 0 and create it again).
One thing I tried was to use NetX instead of NetXDuo. With NetX, it almost connects every time, and the socket is usable after error 7014.