private Connection createWriter(final int serverSocketPort, final boolean isCancelInProgress,
      boolean waitUntilReaderExits)
      throws IOException {
    final ConnectionTable writerTable = mockConnectionTable(waitUntilReaderExits);

    final Membership<InternalDistributedMember> membership = mock(Membership.class);
    final TCPConduit conduit = writerTable.getConduit();
    final InternalDistributedMember remoteAddr =
        new InternalDistributedMember(InetAddress.getLocalHost(), 0, true, true);
    final InternalDistributedMember senderAddr =
        new InternalDistributedMember(InetAddress.getLocalHost(), 1, true, true);

    when(conduit.getCancelCriterion().isCancelInProgress()).thenReturn(isCancelInProgress);
    when(conduit.getMembership()).thenReturn(membership);
    when(conduit.getDM().getCanonicalId(remoteAddr)).thenReturn(remoteAddr);
    when(conduit.getDM().getCanonicalId(senderAddr)).thenReturn(senderAddr);
    when(conduit.getMemberId()).thenReturn(senderAddr);
    when(membership.memberExists(any())).thenReturn(true);

    remoteAddr.setDirectChannelPort(serverSocketPort);
    senderAddr.setDirectChannelPort(conduit.getPort());

    return spy(Connection.createSender(membership, writerTable, true, remoteAddr, true,
        System.currentTimeMillis(), 1000, 1000, false));
  }
Create a sender that connects to the server socket.
geode-core/src/test/java/org/apache/geode/internal/tcp/ConnectionTransmissionTest.java