public void testWebSocketServer() { try { // randomly select two clients from the collection. for (int i = 0; i <= 1000; i++) { NettyTestClient from = clients.get(random.nextInt(clients.size())); NettyTestClient to = clients.get(random.nextInt(clients.size())); // this needs to be here when testing max size or max connections. if (to.isClosed()) { continue; } SocketMessage msg = messages.get(random.nextInt(messages.size())); msg.setText("Hola!"); msg.setFrom(from.getUuid()); msg.setTo(to.getUuid()); msg.setDate(new Date()); String json = JSONUtils.toJson(msg); from.send(json); Thread.sleep(TestConfig.getInstance().getMessageDelay()); } } catch (Exception e) { e.printStackTrace(); } }