I'd like to use the SimpleNetworkWrapper in a setup where the client sends a Request packet to the server, and the server answers with a Reply packet. I have the wrapper set up to a channel, and an appropriate Handler<Request, Reply> registered to a discriminator value. However, when I return new Reply(); from the handler, things start getting seriously weird.
In SSP, things kind of work all right. If I open the game to LAN, and connect with a second client, all reply packets will go to the second client, wherever they originated from. If a third client joins, all reply packets go to the third, etc. If I then disconnect with the last logged in client, the one that got all the reply packets, their target doesn't revert back to the second-last, but the packets will instead disappear into the void.
If I log ctx.getServerHandler().netManager.channel().toString() however, it looks all right, with the correct socket endpoints depending on the source of the request packet. They just get turned around somehow.
With a dedicated server, even one client will have problems. The reply packets sometimes arrive, sometimes not. I did not observe any pattern to it, but I didn't look too long either (I was getting royally frustrated by this point).
I took a look at the SimpleChannelHandlerWrapper class, and it was suspiciously devoid of any mention of FMLOutboundHandler.OutboundTarget.REPLY, which is surprising, since FMLEventChannel uses it when routing reply packets from the packet event.
I tried this just before returning the reply packet:
ctx.getServerHandler().netManager.channel().attr(FMLOutboundHandler.FML_MESSAGETARGET).set(FMLOutboundHandler.OutboundTarget.REPLY);
It didn't work out so well, it set up an infinite loop.
Then I sidestepped the whole issue by doing the following:
simpleNetworkWrapperInstance.sendTo(new Reply(), ctx.getServerHandler().playerEntity);
return null;
Now everything is perfect, works as intended.
Did I miss a setting somewhere, or is SimpleNetworkWrapper borked?
Using Forge 10.12.1.1098.