- To start connecting with sockets, create your connection instance
SocketConnection connection = SocketConnection.serverConnection(port); //Server side
SocketConnection connection = SocketConnection.clientConnection(IP, port); //Client side
- Create a new class implementing
SocketHandler
public class MySocketHandler implements SocketHandler
{
@Override
public void handle(Socket socket, String message)
{
//Your code here
}
}
- Register your handler in your connection instance
connection.addHandler(new MySocketHandler());
- You are ready to go! Start the connection
connection.start();
- I have built-in a duplicate message detector. It is important to prevent duplicates to prevent endless loops for example
- If you want to disable the duplication checker for ONE message use
socket.sendMessage(message, false);
- Please make sure to close the connection if the plugin gets disabled. This is important to prevent errors in the socket pipeline
connection.close();