private void parseCommand(String[] args) { String command = args[0]; switch (command) { case "login": if (args.length != 3) { System.out.println("Wrong login command : login \"login\" \"password\""); return; } api.login(args[1], args[2]); break; case "messageSend": if (args.length != 3) { System.out.println("Wrong messageSend command : messageSend \"chatId\" \"text\""); return; } long chatId = Long.parseLong(args[1]); String text = args[2]; api.messageSend(chatId, text); break; case "joinGroup": if (args.length != 2) { System.out.println("Wring joinGroup command : joinGroup \"chatId\""); return; } chatId = Long.parseLong(args[1]); api.joinChat(chatId); break; case "killClient": killClient(); break; } }
public void startUdpListener(List<Chat> subscribedChats) { try { udpHandler = new UdpHandler(subscribedChats, Constants.BROADCAST_PORT, this); System.out.println("start udp listener"); } catch (IOException e) { e.printStackTrace(); // Something goes wrong, break client killClient(); } }
public void leaveChat(String address) { try { udpHandler.leaveGroup(address); } catch (IOException e) { System.out.println("Client: leaveChat: error in leaving chat = " + address); e.printStackTrace(); // Something goes wrong, break client killClient(); } }