Skip to content

Commit ee66f69

Browse files
committed
Introduced sending objects without the usage of a packet, as Hydra handles that internally with a StandardPacket class. Therefore reworked the examples and provided explanations for the usage. Also added javadoc for the new introduced methods. Bumped to version 1.5.0.
1 parent c91a5ba commit ee66f69

File tree

14 files changed

+98
-12
lines changed

14 files changed

+98
-12
lines changed

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ like a [simple chat application](https://github.com/DataSecs/Hydra/wiki/Building
3636
<dependency>
3737
<groupId>de.datasecs</groupId>
3838
<artifactId>hydra-all</artifactId>
39-
<version>1.4.7</version>
39+
<version>1.5.0</version>
4040
</dependency>
4141
```
4242

@@ -46,7 +46,7 @@ like a [simple chat application](https://github.com/DataSecs/Hydra/wiki/Building
4646
<dependency>
4747
<groupId>de.datasecs</groupId>
4848
<artifactId>hydra-all</artifactId>
49-
<version>1.4.5</version>
49+
<version>1.5.0</version>
5050
</dependency>
5151
```
5252

all/pom.xml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.4.7</version>
8+
<version>1.5.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,14 +16,14 @@
1616
<dependency>
1717
<groupId>de.datasecs</groupId>
1818
<artifactId>hydra-client</artifactId>
19-
<version>1.4.7</version>
19+
<version>1.5.0</version>
2020
</dependency>
2121

2222
<!-- Hydra server -->
2323
<dependency>
2424
<groupId>de.datasecs</groupId>
2525
<artifactId>hydra-server</artifactId>
26-
<version>1.4.7</version>
26+
<version>1.5.0</version>
2727
</dependency>
2828
</dependencies>
2929

client/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.4.7</version>
8+
<version>1.5.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>de.datasecs</groupId>
1818
<artifactId>hydra-shared</artifactId>
19-
<version>1.4.7</version>
19+
<version>1.5.0</version>
2020
</dependency>
2121
</dependencies>
2222

client/src/main/java/de/datasecs/hydra/client/HydraClient.java

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
import io.netty.channel.Channel;
1010
import io.netty.channel.EventLoopGroup;
1111

12+
import java.io.Serializable;
1213
import java.net.SocketAddress;
1314

1415
/**
@@ -94,6 +95,19 @@ public void send(Packet packet) {
9495
clientSession.send(packet);
9596
}
9697

98+
/**
99+
* Sends a packet to the opponent that is connected with this session. With the difference that the param not is a
100+
* packet. The packet is created internally and then send to the opponent, so the user doesn't have to bother with
101+
* the packet creation. Therefore the object that is passed to the method has to be serializable.
102+
* See {@link de.datasecs.hydra.shared.protocol.packets.StandardPacket} for the structure of the standard packet.
103+
*
104+
* @param object the object that is supposed to be send to the opponent of the session.
105+
*/
106+
public <T extends Serializable> void send(T object) {
107+
checkChannel();
108+
clientSession.send(object);
109+
}
110+
97111
/**
98112
* Returns the channel (a connection/pipeline) that was created for the server. The channel allows a lot of functionality.
99113
* The channel provides information about the channel configuration, the channel state, the channel pipeline and much

client/src/test/java/client/ExampleClient.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,12 @@ public void onDisconnected(Session session) {
5757
session.send(new SamplePacket("This is a message", new String[]{"This", "is", "a", "message"}));
5858
// Sends a list, that is converted to a Object and the array, like above
5959
session.send(new SamplePacket(Arrays.asList("This", "is", "a", "message", "2"), new String[]{"This", "is", "a", "message", "2"}));
60+
/* Sends an object the user wants to send with the limitation that the object has to be serializable.
61+
* Hydra internally uses a standard packet that comes ready out of the box. The only thing that is important to notice
62+
* is the fact, that the Handler for the packet still has to be created by the user itself. Therefore see
63+
* the SamplePacketListener of the server example classes.
64+
*/
65+
session.send("This is a String and dealt with as object by Hydra");
6066

6167
// Closes the connection and releases all occupied resources
6268
//client.close();

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<groupId>de.datasecs</groupId>
88
<artifactId>hydra</artifactId>
99
<packaging>pom</packaging>
10-
<version>1.4.7</version>
10+
<version>1.5.0</version>
1111

1212
<modules>
1313
<module>all</module>

server/pom.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.4.7</version>
8+
<version>1.5.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

@@ -16,7 +16,7 @@
1616
<dependency>
1717
<groupId>de.datasecs</groupId>
1818
<artifactId>hydra-shared</artifactId>
19-
<version>1.4.7</version>
19+
<version>1.5.0</version>
2020
</dependency>
2121
</dependencies>
2222

server/src/test/java/server/SamplePacketListener.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package server;
22

33
import de.datasecs.hydra.shared.handler.Session;
4+
import de.datasecs.hydra.shared.protocol.packets.StandardPacket;
45
import de.datasecs.hydra.shared.protocol.packets.listener.HydraPacketListener;
56
import de.datasecs.hydra.shared.protocol.packets.listener.PacketHandler;
67
import server.packets.SamplePacket;
@@ -52,4 +53,14 @@ public void onSampleSerializationPacket(SampleSerializationPacket sampleSerializ
5253
session.close();
5354
System.out.println("\nSession closed!");
5455
}
56+
57+
@PacketHandler
58+
public void onStandardPacket(StandardPacket standardPacket, Session session) {
59+
System.out.println("\n---PACKET-LISTENER OUTPUT---");
60+
61+
System.out.printf("Received from client using the StandardPacket: %s%n", standardPacket);
62+
63+
session.close();
64+
System.out.println("\nSession closed!");
65+
}
5566
}

shared/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
<parent>
66
<artifactId>hydra</artifactId>
77
<groupId>de.datasecs</groupId>
8-
<version>1.4.7</version>
8+
<version>1.5.0</version>
99
</parent>
1010
<modelVersion>4.0.0</modelVersion>
1111

shared/src/main/java/de/datasecs/hydra/shared/handler/HydraSession.java

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,12 @@
22

33
import de.datasecs.hydra.shared.protocol.HydraProtocol;
44
import de.datasecs.hydra.shared.protocol.packets.Packet;
5+
import de.datasecs.hydra.shared.protocol.packets.StandardPacket;
56
import io.netty.channel.Channel;
67
import io.netty.channel.ChannelHandlerContext;
78
import io.netty.channel.SimpleChannelInboundHandler;
89

10+
import java.io.Serializable;
911
import java.net.SocketAddress;
1012

1113
/**
@@ -43,6 +45,11 @@ public void send(Packet packet) {
4345
channel.writeAndFlush(packet);
4446
}
4547

48+
@Override
49+
public <T extends Serializable> void send(T object) {
50+
channel.writeAndFlush(new StandardPacket(object));
51+
}
52+
4653
@Override
4754
public void close() {
4855
channel.disconnect();

0 commit comments

Comments
 (0)