Skip to content

Packet Responses

gcflames5 edited this page Aug 24, 2014 · 2 revisions

When creating a new Packet, you have the option to indicate that the packet is a response to another packet through setResponse(Packet packet). The AutoResponder class allows you to perform an action when you receive a packet in response to the indicated packet.

Example:

ResponseUtil.getDefaultResponder().onResponse(sentPacket, new Response() {
    @Override
    public void run() {
        Packet receivedPacket = packet;
        Connection connection = event.getConnection();
        //Handle response
    }
});

The packet and event variables are set for you in Response automagically.

Clone this wiki locally