use of de.datasecs.hydra.shared.handler.Session in project Hydra by DataSecs.
the class ChatClient method main.
public static void main(String[] args) {
HydraClient hydraClient = new Client.Builder("localhost", 8888, new ChatClientProtocol()).addSessionListener(new HydraSessionListener() {
@Override
public void onConnected(Session session) {
System.out.println("You are connected to the server!");
}
@Override
public void onDisconnected(Session session) {
System.out.printf("You were disconnected from the server with ip: %s%n", session.getAddress());
}
}).option(ChannelOption.TCP_NODELAY, true).build();
BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
String input;
MessagePacket messagePacket = new MessagePacket();
while (true) {
try {
input = bufferedReader.readLine();
if (input.equalsIgnoreCase("#end")) {
System.out.println("Disconnecting from chat...");
hydraClient.send(new ServerPacket("disconnect"));
hydraClient.close();
System.out.println("Disconnected!");
return;
}
messagePacket.setMessage(String.format("%s;%s;%s", hydraClient.getLocalAddress(), Calendar.getInstance().getTime().toString(), input));
hydraClient.send(messagePacket);
} catch (IOException e) {
e.printStackTrace();
}
}
}
Aggregations