Jump to content
Search In
  • More options...
Find results that contain...
Find results in...

[1.7.10] SimpleChannelHandlerWrapper exception (Client to Server only)


Belpois
 Share

Recommended Posts

Hey, so I am trying to send a packet from the client to the server which contains a simple heartbeat test (Wrote this to debug), note that server to client works :-\

 

Here is the code:

 

Common Proxy

NetMgr.channel.registerMessage(ServerHeartbeat.Handler.class, ServerHeartbeat.class, 0, Side.SERVER);
NetMgr.channel.registerMessage(ClientHeartbeat.Handler.class, ClientHeartbeat.class, 1, Side.CLIENT);

 

On item right click

if (world.isRemote)
{
        // Testing parameters [par1: random string, par2: random number]
NetMgr.channel.sendToServer(new Heartbeat("This is client", );
}

 

Heartbeat Class (Same for both Server and Client, the difference is the class name)

public class ClientHeartbeat implements IMessage
{
private String name = "";
private int secretNumber = 0;

public ClientHeartbeat()
{

}

public ClientHeartbeat(String name, int secretNumber)
{
	this.name = name;
	this.secretNumber = secretNumber;
}

@Override
public void fromBytes(ByteBuf byteBuf)
{
	this.name = this.readString(byteBuf);
	this.secretNumber = byteBuf.readInt();
}

@Override
public void toBytes(ByteBuf byteBuf)
{
	this.writeString(byteBuf, this.name);
	byteBuf.writeInt(this.secretNumber);
}

public void writeString(ByteBuf output, String s)
{
	output.writeInt(s.getBytes().length);
	output.writeBytes(s.getBytes());
}

public String readString(ByteBuf byteBuf)
{
	return new String(byteBuf.readBytes(byteBuf.readInt()).array());
}

public static class Handler implements IMessageHandler<Heartbeat, IMessage>
{
	@Override
	public IMessage onMessage(Heartbeat heartbeat, MessageContext messageContext)
	{
		LogHelper.info("PP Client Heartbeat");
		return null;
	}
}
}

 

Client Error

[19:41:08] [Client thread/ERROR]: SimpleChannelHandlerWrapper exception

java.lang.RuntimeException: Missing

at cpw.mods.fml.server.FMLServerHandler.getClientToServerNetworkManager(FMLServerHandler.java:238) ~[FMLServerHandler.class:?]

at cpw.mods.fml.common.FMLCommonHandler.getClientToServerNetworkManager(FMLCommonHandler.java:530) ~[FMLCommonHandler.class:?]

at cpw.mods.fml.common.network.FMLOutboundHandler$OutboundTarget$8.selectNetworks(FMLOutboundHandler.java:225) ~[FMLOutboundHandler$OutboundTarget$8.class:?]

at cpw.mods.fml.common.network.FMLOutboundHandler.write(FMLOutboundHandler.java:273) ~[FMLOutboundHandler.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:637) ~[DefaultChannelHandlerContext.class:?]

at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115) ~[MessageToMessageEncoder.class:?]

at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:?]

at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:644) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:698) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:688) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:717) ~[DefaultChannelHandlerContext.class:?]

at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:?]

at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:239) ~[AbstractChannel.class:?]

at cpw.mods.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(SimpleNetworkWrapper.java:236) [simpleNetworkWrapper.class:?]

at com.me.pp.item.ItemPP.onItemRightClick(ItemPP.java:70) [itemPP.class:?]

at net.minecraft.item.ItemStack.useItemRightClick(ItemStack.java:146) [itemStack.class:?]

at net.minecraft.client.multiplayer.PlayerControllerMP.sendUseItem(PlayerControllerMP.java:377) [PlayerControllerMP.class:?]

at net.minecraft.client.Minecraft.func_147121_ag(Minecraft.java:1463) [Minecraft.class:?]

at net.minecraft.client.Minecraft.runTick(Minecraft.java:1941) [Minecraft.class:?]

at net.minecraft.client.Minecraft.runGameLoop(Minecraft.java:961) [Minecraft.class:?]

at net.minecraft.client.Minecraft.run(Minecraft.java:887) [Minecraft.class:?]

at net.minecraft.client.main.Main.main(SourceFile:148) [Main.class:?]

at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[?:1.7.0_72]

at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[?:1.7.0_72]

at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[?:1.7.0_72]

at java.lang.reflect.Method.invoke(Method.java:606) ~[?:1.7.0_72]

at net.minecraft.launchwrapper.Launch.launch(Launch.java:135) [launchwrapper-1.11.jar:?]

at net.minecraft.launchwrapper.Launch.main(Launch.java:28) [launchwrapper-1.11.jar:?]

at net.minecraftforge.gradle.GradleStartCommon.launch(GradleStartCommon.java:78) [start/:?]

at GradleStart.main(GradleStart.java:45) [start/:?]

 

Extra Notes, so I debugged the code and led me to a java class named "FMLCommonHandler" -> "FMLServerHandler", seems that the code is executing to this method:

 

public NetworkManager getClientToServerNetworkManager() {
    return this.sidedDelegate.getClientToServerNetworkManager();
}

public NetworkManager getClientToServerNetworkManager() {
    throw new RuntimeException("Missing");
}

 

Hope that extra code helps :), Thanks!

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

This is the heartbeat class, client and server are the same, the difference is the name:

 

public class ClientHeartbeat implements IMessage
{
private String name = "";
private int secretNumber = 0;

public ClientHeartbeat()
{

}

public ClientHeartbeat(String name, int secretNumber)
{
	this.name = name;
	this.secretNumber = secretNumber;
}

@Override
public void fromBytes(ByteBuf byteBuf)
{
	this.name = this.readString(byteBuf);
	this.secretNumber = byteBuf.readInt();
}

@Override
public void toBytes(ByteBuf byteBuf)
{
	this.writeString(byteBuf, this.name);
	byteBuf.writeInt(this.secretNumber);
}

public void writeString(ByteBuf output, String s)
{
	output.writeInt(s.getBytes().length);
	output.writeBytes(s.getBytes());
}

public String readString(ByteBuf byteBuf)
{
	return new String(byteBuf.readBytes(byteBuf.readInt()).array());
}

public static class Handler implements IMessageHandler<Heartbeat, IMessage>
{
	@Override
	public IMessage onMessage(Heartbeat heartbeat, MessageContext messageContext)
	{
		LogHelper.info("PP Client Heartbeat");
		return null;
	}
}
}

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

So after a bit of variable watching and swearing at my PC for not working, this is what I found. TLDR at the bottom of post :)

 

I put a watch on these four instances and methods:

 

FMLCommonHandler.instance().getEffectiveSide()
FMLCommonHandler.instance().getSide()

FMLClientHandler.instance().getClient().isSingleplayer()
FMLClientHandler.instance().getServer().isPublic

 

When remote was true (client), getEffectiveSide was "Side.CLIENT" but getSide() was "Side.Server" which messed up the whole channel, even my GUI's where not working as they were trying to execute on the server.

 

This code below is found in the FMLNetworkHandler, checks if client to open the GUI, as it tried to check if its client, theMC internal state was server and it messed up.

FMLCommonHandler.instance().getSide().equals(Side.CLIENT)

 

Now obviously the dedicated server was working perfectly as everything is executed server side, and I asked my self what was wrong in the execution path of my Client Debug and my Server Debug Environments?

 

Two words, "Watched List"... I had this expression in the watches list "FMLClientHandler.instance().getServer().isPublic" to check if the current world is open to LAN but "isPublic" is only available when you cast the return of getServer(), which is MinecraftServer to IntegratedServer as the "isPublic" field only exists in IntegratedServer...

 

What I guess is that the exception was causing the debugger to act weirdly and throw an exception that the IDE catches but messed up the MC State, and since the watches where only on the clients debugger the server worked normally. Weird huh! :P

 

Sorry for the long post.

 

TLDR

Had watched expression throwing an exception messing up Minecraft's execution path, at least thats what I think.

 

Can I cry now?  :'(

 

I require Java, both the coffee and the code :)

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share



×
×
  • Create New...

Important Information

By using this site, you agree to our Terms of Use.