Socket connect(Address address) throws CommunicationException {
		Socket socket;
		InetAddress inetAddress = null;

		try {
			if (m_socket != null) {
				inetAddress = m_socket.getInetAddress();
				socket = m_socket;
			} else {
				try {
					inetAddress = InetAddress.getByName(m_hostString);
					socket = new Socket(inetAddress, m_port);
				}
				catch (UnknownHostException e) {
					throw new CommunicationException(
						"Could not resolve host '" + m_hostString + '\'', e);
				}
			}

			final OutputStream outputStream = socket.getOutputStream();

			final ObjectOutputStream objectStream =
				new ObjectOutputStream(outputStream);
			objectStream.writeObject(m_connectionType);
			objectStream.writeObject(address);
			objectStream.flush();
			return socket;
		}
		catch (IOException e) {
			UncheckedInterruptedException.ioException(e);
			throw new CommunicationException(
				"Failed to connect to '" + inetAddress + ':' + m_port + '\'', e);
		}
	}
Factory method that makes a TCP connection and returns a
corresponding socket.

@return A socket wired to the connection.
@throws CommunicationException If connection could not be
establish.
ngrinder-core/src/main/java/net/grinder/communication/Connector.java