InetAddress bindAddress = InetAddress.getByName(getHostName());
int bindPort = PortUtil.findFreePort(getHostName());
InetSocketAddress bindSocketAddress = new InetSocketAddress(bindAddress, bindPort);
InetSocketAddress connectSocketAddress = new InetSocketAddress(serverAddress, serverPort);
socket.connect(connectSocketAddress, bindSocketAddress, 0);
InputStream is = socket.getInputStream();
OutputStream os = socket.getOutputStream();
os.write(7);
assertEquals(7, is.read());
socket.close();