use of de.datasecs.hydra.shared.protocol.packets.listener.PacketHandler in project Hydra by DataSecs.
the class SamplePacketListener method onSamplePacket.
/* Use the @PacketHandler annotation on methods that are supposed to handle packets.
* The amount of parameters has always to be equal 2 and in the given order. (Packet class and then the session)
*/
@PacketHandler
public void onSamplePacket(SamplePacket samplePacket, Session session) {
System.out.println("\n---PACKET-LISTENER OUTPUT---");
// Process received packet
System.out.printf("Received from client: %s%n", samplePacket);
// Send response
session.send(new SamplePacket("This is a response", new String[] { "This", "is", "a", "response" }));
// Returns whether the session is active
System.out.println("\nIs session active?: " + session.isConnected());
// Returns the local or remote address, depending if it's the server or the client
System.out.println("Local server address: " + session.getAddress());
// TODO: See if it can be checked whether the session is already closed and return a boolean for that
// Closes the session, this does not stop the server. It just closes the channel!
session.close();
System.out.println("\nSession closed!");
// Check again if session is active
System.out.println("Is session active?: " + session.isConnected());
}
use of de.datasecs.hydra.shared.protocol.packets.listener.PacketHandler in project Hydra by DataSecs.
the class ExampleServerPacketListener method onSamplePacket.
/* Use the @PacketHandler annotation on methods that are supposed to handle packets.
* The amount of parameters has always to be equal 2 and in the given order. (Packet class and then the session)
*/
@PacketHandler
public void onSamplePacket(ExamplePacket examplePacket, Session session) {
System.out.println("\n---PACKET-LISTENER OUTPUT---");
// Process received packet
System.out.printf("Received from client: %s%n", examplePacket);
// Send response
session.send(new ExamplePacket("This is a response", new String[] { "This", "is", "a", "response" }));
// Returns whether the session is active
System.out.println("\nIs session active?: " + session.isConnected());
// Returns the local or remote address, depending if it's the server or the client
System.out.println("Local server address: " + session.getAddress());
// TODO: See if it can be checked whether the session is already closed and return a boolean for that
// Closes the session, this does not stop the server. It just closes the channel!
session.close();
System.out.println("\nSession closed!");
// Check again if session is active
System.out.println("Is session active?: " + session.isConnected());
}
use of de.datasecs.hydra.shared.protocol.packets.listener.PacketHandler in project Hydra by DataSecs.
the class TestServerPacketListener method onStandardPacket.
@PacketHandler
public void onStandardPacket(StandardPacket standardPacket, Session session) {
Assertions.assertTrue(session.isConnected());
session.send(new StandardPacket("#Received!"));
}
use of de.datasecs.hydra.shared.protocol.packets.listener.PacketHandler in project Hydra by DataSecs.
the class TestServerPacketListener method onTestPacket.
@PacketHandler
public void onTestPacket(TestPacket examplePacket, Session session) {
Assertions.assertTrue(session.isConnected());
switch(examplePacket.getNumber()) {
case 0:
Assertions.assertEquals("Test", examplePacket.getObject().toString());
break;
}
session.send(new StandardPacket("#Received!"));
session.send(new TestPacket(examplePacket.getNumber(), "test"));
}
Aggregations