@Test
    public void testClientMessaging() {
        System.out.println("testClientMessaging");

        try {
            assertTrue(c.registerToServer(GlobalConstants.IP_LOOPBACK));
        } catch (Exception ex) {
            fail("Registration from client to server failed - " + ex);
        }

        s.getListenerRegistrator().setClientListener(c.getLocalID(), new Listener<DataPacket>() {
            @Override
            public Object receiveData(DataPacket data) {
                if (data.getData() instanceof Message) {
                    final Message m = (Message) data.getData();
                    StringBuilder sb = new StringBuilder(m.getHeader());
                    return sb.reverse().toString();
                } else {
                    return GenericResponses.OK;
                }
            }
        });
        c.getListenerRegistrator().setClientListener(s.getId(), new Listener<DataPacket>() {
            @Override
            public Object receiveData(DataPacket data) {
                if (data.getData() instanceof Message) {
                    final Message m = (Message) data.getData();
                    StringBuilder sb = new StringBuilder(m.getHeader());
                    return sb.reverse().toString();
                } else {
                    return GenericResponses.OK;
                }
            }
        });

        final String header = "abcdefg";
        final Message m = new Message(header, "data");

        final StringBuilder sb = new StringBuilder(header);
        final String reverseHeader = sb.reverse().toString();

        try {
            assertEquals(reverseHeader, c.sendDataToServer(m));
            assertEquals(GenericResponses.OK, c.sendDataToServer(header));

            assertEquals(reverseHeader, s.getClient(c.getLocalID()).sendData(m));
            assertEquals(GenericResponses.OK, s.getClient(c.getLocalID()).sendData(header));
        } catch (ConnectionException ex) {
            fail("Communication failed - " + ex);
        }

        c.getListenerRegistrator().removeClientListener(s.getId());
        try {
            assertEquals(GenericResponses.NOT_HANDLED, s.getClient(c.getLocalID()).sendData(m));
        } catch (ConnectionException ex) {
            Logger.getLogger(MessagingTest.class.getName()).log(Level.SEVERE, null, ex);
        }
    }