-
Notifications
You must be signed in to change notification settings - Fork 0
Sending Packets
The method to sending packets can differ based on what network structure you're using, and that is why it has a dedicated page.
Basic Client (Unauthenticated): simply get the connection and call sendPacket(Packet p)
TcpClientManager manager; //see wiki for "Basic Client" tutorial
manager.getConnection().sendPacket(myPacket);Basic Server (Unauthenticated): loop through connections, get deisred one, and call sendPacket(Packet p), (ideally, you might want to hold a connection inside something like a User class and send packets that way:
TcpServerManager manager; //see wiki for "Basic Server" tutorial
manager.getConnections().get(0).sendPacket(myPacket);Authenticated Client: similar to TcpClientManager, but AuthenticatedTcpClientManager has a method sendPacketSafely(Packet p) that will only send the packet once authentication has completed, additionally, you can still call getConnection() and send packets regardless of authentication:
AuthenticatedTcpClientManager manager; //see wiki for "Authenticated Client" tutorial
manager.sendPacketSafely(myPacket);
/* OR */
manager.getConnection().sendPacket(myPacket); //force send even if not authenticated (may be rejected)Authenticated Server: exactly the same as TcpServerManager (see above)
Mesh Network (Unauthenticated): When sending a packet in a mesh network, that packet is sent to all connected entities. (If you do not desire this functionality consider a different network structure) To send a packet in a mesh, call broadcast() on the mesh's ``MeshServerManager```:
Mesh mesh; //see wiki for "Mesh Network" tutorial
mesh.getManager().broadcast(myPacket);Authenticated Mesh Network: Like a unauthenticated mesh, all packets are sent to all entities. Similar to AuthenticatedTcpManager, the AuthenticatedMesh class contains a sendPacketSafely(Packet p) method that will only send packets after authorization.
AuthenticatedMesh mesh; //see wiki for "Authenticated Mesh" tutorial
mesh.sendPacketSafely(myPacket); //Broadcast to all entities
/* OR */
mesh.getServerManager().getConnections().get(0).sendPacket(myPacket); //force send even if not authenticated (may be rejected)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