I’am trying to send a packet to the server from my forge mod ( client side). And i want to receive this packet in my sponge plugin. So i used ChannelRegistrar etc… BUT! Nothing is happening, nothing is printing in the terminal.
Here my code :
This is supposed to work and at least show the “works” message in the handler class when i receive my packet (last sponge class that i linked ).
I have no error in my terminal…
Please guys I’m struggling on this issue for few days…
Unfortunately I don’t know the solution, but I want to push this topic because I faced the same challenge this weekend. I would also appreciate any help, because I need to communicate between my plugin and my mod. For example to open a custom GUI on client side and to transfer the result to the server to store the result inside a database and to work with the data in my plugin.
Well, Sponge networking API (or how this thing is named) is somewhy poorly documented, so yeah, it’s easy to stuck there.
I’m going to help you by giving examples of code I use in my plugin. They work normally.
First off: channel registering (done in init, but I think it doesn’t matter when you register your channel)
public class ExampleListener implements RawDataListener {
@Override
public void handlePayload(ChannelBuf buf, RemoteConnection connection, Platform.Type side) {
if (!(connection instanceof PlayerConnection)) {
return;
}
Player player = ((PlayerConnection) connection).getPlayer();
// Do your stuff here.
}
}
And now, simply invoke yourChannel.addListener(new ExampleListener())
That’s it.