-
Notifications
You must be signed in to change notification settings - Fork 0
Packets
gcflames5 edited this page Aug 23, 2014
·
15 revisions
ServerInterconnect supports 2 types of Packets, a default Packet and a JsonPacket. These 2 packets are identical except in the way that they are serialized. A Packet requires the implementing class to specify read and write methods that read/write all relevant information to and from a data stream. A JsonPacket uses the GSON Library to serialize all the fields contained in the packet class into JSON.
Creating a regular packet:
Packet Requirements:
- A default constructor that is public and takes no args
- A
readPacketContent(DataInputStream input)method that populates instance variables from aDataInputStream - A
writePacketContent(DataOutputStream output)method that writes instance variables to aDataOutputStream
class NewPacket extends Packet{
private String testString;
public NewPacket(){} //MUST be present
public NewPacket(String testString){
this.testString = testString;
}
@Override
public void readPacketContent(DataInputStream input) throws IOException {
testString = Packet.readString(input);
}
@Override
public void writePacketContent(DataOutputStream output) throws IOException {
Packet.writeString(testString, output);
}
//remember to read/write in the same order!
}Basic IO
Basic Client
Basic Server
Authenticated IO
Authenticated Client
Authenticated Server
Mesh
Mesh Network
Authenticated Mesh
Packets
Creating Packets
Sending Packets
Listening for Packets
Automatic Handlers
Response Handlers
UPnP
Port Forwarding