Skip to content

Sending Packets

gcflames5 edited this page Aug 26, 2014 · 5 revisions

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:

```java
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)

Clone this wiki locally