1
Sending data Server <-> Client
Hi all,
I'm STILL having problems with my mod:
I try to save progress of the player on an associated class in a file.
This works for client and server.
BUT when I try to open the file (not the problem), I try to load it.
This all works well on the client,
but I can't seem to send to opened data to the client, modify it and send it back...
Is there an (easy) way to send this info, perhaps via packages or something?
I load my data in an array list and get my info from there.
One of the problems: I open the file at server start, but when I try to get the info from the server via the client, this list and the save file location are null (as I use a different location for server and client).
So basically:
I want to get the server (when you join) and send the save file from the server to the client
Then I can edit it and send the edited info back.
Or I can edit the file, save and reload it...
Thanks in advance!
I'm STILL having problems with my mod:
I try to save progress of the player on an associated class in a file.
This works for client and server.
BUT when I try to open the file (not the problem), I try to load it.
This all works well on the client,
but I can't seem to send to opened data to the client, modify it and send it back...
Is there an (easy) way to send this info, perhaps via packages or something?
I load my data in an array list and get my info from there.
One of the problems: I open the file at server start, but when I try to get the info from the server via the client, this list and the save file location are null (as I use a different location for server and client).
So basically:
I want to get the server (when you join) and send the save file from the server to the client
Then I can edit it and send the edited info back.
Or I can edit the file, save and reload it...
Thanks in advance!
Create an account or sign in to comment.
9
1
Ahh understandable, I'm not exactly sure where or why your code is crashing though. Id need to test it out myself
1
The reason I'm sending the path, is because the file content is stored in an arraylist, but this arraylist is of type: A custom class, which contains 2 variables.
1. Playername
2. Knight class, which again contains 5 variables
So it's easier to send my path, because then the server knows it's been edited and to reload the file
1. Playername
2. Knight class, which again contains 5 variables
So it's easier to send my path, because then the server knows it's been edited and to reload the file
1
You seem to be sending the file path over rather than the file contents, atm i dont understand why but yea. As far as I can see thought I dunno why its not working. I cant tell from the lines its crashing on due to pastebin but yea. Maybe there are unallowed symbols or your sending null(not sure if thats allowed) but something is playing up, it could be in the string encoding.
1
You can find all you need here: http://pastebin.com/RFuRgqPq
Let me know if you need something else
Thanks in advance!
Maybe somewhat relevant: I work in MC 1.8, but everything you do in your github works for me...
I tried to keep it as close to your examples as possible, since you have a very clean code
Let me know if you need something else
Thanks in advance!
Maybe somewhat relevant: I work in MC 1.8, but everything you do in your github works for me...
I tried to keep it as close to your examples as possible, since you have a very clean code
1
Could you send me snippets of where your sending the packets and also where your registering them?
1
Previously I got this error, because it wasn't registered...
Now everything is registered and I still get the error
Now everything is registered and I still get the error
1
Ok, so sending to the client works perfectly, but now I have a problem sending the edited info back... I do completely the same, but for the server and it gives me the following exception:
Click to reveal
[17:51] [Server thread/ERROR] [FML]: SimpleChannelHandlerWrapper exception
java.lang.RuntimeException: Missing
at net.minecraftforge.fml.server.FMLServerHandler.getClientToServerNetworkManager(Unknown Source) ~[FMLServerHandler.class:?]
at net.minecraftforge.fml.common.FMLCommonHandler.getClientToServerNetworkManager(Unknown Source) ~[FMLCommonHandler.class:?]
at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$8.selectNetworks(Unknown Source) ~[FMLOutboundHandler$OutboundTarget$8.class:?]
at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(Unknown Source) ~[FMLOutboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:638) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115) ~[MessageToMessageEncoder.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:689) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:718) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:240) ~[AbstractChannel.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(Unknown Source) [SimpleNetworkWrapper.class:?]
at com.quickscop3s.CastleDefendersMod.packets.PacketDispatcher.sendPacketToServer(PacketDispatcher.java:10) [PacketDispatcher.class:?]
at com.quickscop3s.CastleDefendersMod.knight.KnightDataManager.sendToServer(KnightDataManager.java:123) [KnightDataManager.class:?]
at com.quickscop3s.CastleDefendersMod.knight.KnightDataManager.addPlayerData(KnightDataManager.java:88) [KnightDataManager.class:?]
at com.quickscop3s.CastleDefendersMod.knight.KnightClassManager.joinClass(KnightClassManager.java:71) [KnightClassManager.class:?]
at com.quickscop3s.CastleDefendersMod.commands.CommandKnightClass.execute(CommandKnightClass.java:61) [CommandKnightClass.class:?]
at net.minecraft.command.CommandHandler.tryExecute(Unknown Source) [CommandHandler.class:?]
at net.minecraft.command.CommandHandler.executeCommand(Unknown Source) [CommandHandler.class:?]
at net.minecraft.network.NetHandlerPlayServer.handleSlashCommand(Unknown Source) [NetHandlerPlayServer.class:?]
at net.minecraft.network.NetHandlerPlayServer.processChatMessage(Unknown Source) [NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C01PacketChatMessage.processPacket(Unknown Source) [C01PacketChatMessage.class:?]
at net.minecraft.network.play.client.C01PacketChatMessage.processPacket(Unknown Source) [C01PacketChatMessage.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(Unknown Source) [PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_60]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(Unknown Source) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(Unknown Source) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(Unknown Source) [DedicatedServer.class:?]
at net.minecraft.server.MinecraftServer.tick(Unknown Source) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(Unknown Source) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
java.lang.RuntimeException: Missing
at net.minecraftforge.fml.server.FMLServerHandler.getClientToServerNetworkManager(Unknown Source) ~[FMLServerHandler.class:?]
at net.minecraftforge.fml.common.FMLCommonHandler.getClientToServerNetworkManager(Unknown Source) ~[FMLCommonHandler.class:?]
at net.minecraftforge.fml.common.network.FMLOutboundHandler$OutboundTarget$8.selectNetworks(Unknown Source) ~[FMLOutboundHandler$OutboundTarget$8.class:?]
at net.minecraftforge.fml.common.network.FMLOutboundHandler.write(Unknown Source) ~[FMLOutboundHandler.class:?]
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:638) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageEncoder.write(MessageToMessageEncoder.java:115) ~[MessageToMessageEncoder.class:4.0.15.Final]
at io.netty.handler.codec.MessageToMessageCodec.write(MessageToMessageCodec.java:116) ~[MessageToMessageCodec.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.invokeWrite(DefaultChannelHandlerContext.java:645) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.write(DefaultChannelHandlerContext.java:699) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:689) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelHandlerContext.writeAndFlush(DefaultChannelHandlerContext.java:718) ~[DefaultChannelHandlerContext.class:4.0.15.Final]
at io.netty.channel.DefaultChannelPipeline.writeAndFlush(DefaultChannelPipeline.java:893) ~[DefaultChannelPipeline.class:4.0.15.Final]
at io.netty.channel.AbstractChannel.writeAndFlush(AbstractChannel.java:240) ~[AbstractChannel.class:4.0.15.Final]
at net.minecraftforge.fml.common.network.simpleimpl.SimpleNetworkWrapper.sendToServer(Unknown Source) [SimpleNetworkWrapper.class:?]
at com.quickscop3s.CastleDefendersMod.packets.PacketDispatcher.sendPacketToServer(PacketDispatcher.java:10) [PacketDispatcher.class:?]
at com.quickscop3s.CastleDefendersMod.knight.KnightDataManager.sendToServer(KnightDataManager.java:123) [KnightDataManager.class:?]
at com.quickscop3s.CastleDefendersMod.knight.KnightDataManager.addPlayerData(KnightDataManager.java:88) [KnightDataManager.class:?]
at com.quickscop3s.CastleDefendersMod.knight.KnightClassManager.joinClass(KnightClassManager.java:71) [KnightClassManager.class:?]
at com.quickscop3s.CastleDefendersMod.commands.CommandKnightClass.execute(CommandKnightClass.java:61) [CommandKnightClass.class:?]
at net.minecraft.command.CommandHandler.tryExecute(Unknown Source) [CommandHandler.class:?]
at net.minecraft.command.CommandHandler.executeCommand(Unknown Source) [CommandHandler.class:?]
at net.minecraft.network.NetHandlerPlayServer.handleSlashCommand(Unknown Source) [NetHandlerPlayServer.class:?]
at net.minecraft.network.NetHandlerPlayServer.processChatMessage(Unknown Source) [NetHandlerPlayServer.class:?]
at net.minecraft.network.play.client.C01PacketChatMessage.processPacket(Unknown Source) [C01PacketChatMessage.class:?]
at net.minecraft.network.play.client.C01PacketChatMessage.processPacket(Unknown Source) [C01PacketChatMessage.class:?]
at net.minecraft.network.PacketThreadUtil$1.run(Unknown Source) [PacketThreadUtil$1.class:?]
at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source) [?:1.8.0_60]
at java.util.concurrent.FutureTask.run(Unknown Source) [?:1.8.0_60]
at net.minecraftforge.fml.common.FMLCommonHandler.callFuture(Unknown Source) [FMLCommonHandler.class:?]
at net.minecraft.server.MinecraftServer.updateTimeLightAndEntities(Unknown Source) [MinecraftServer.class:?]
at net.minecraft.server.dedicated.DedicatedServer.updateTimeLightAndEntities(Unknown Source) [DedicatedServer.class:?]
at net.minecraft.server.MinecraftServer.tick(Unknown Source) [MinecraftServer.class:?]
at net.minecraft.server.MinecraftServer.run(Unknown Source) [MinecraftServer.class:?]
at java.lang.Thread.run(Unknown Source) [?:1.8.0_60]
1
Thank you very much, I'll try this out immediately!
Ps. Where would I put the output/Input stream?
Ps. Where would I put the output/Input stream?
1
Here are some snippets from one of my mods as an example, first youll need to register a packet network in the preinit.
packetNetwork = NetworkRegistry.INSTANCE.newSimpleChannel("SNM");
packetNetwork.registerMessage(ClientParticleEffectPacket.class, ClientParticleEffectPacket.class, 0, Side.CLIENT);
packetNetwork.registerMessage(ServerParticleEffectPacket.class, ServerParticleEffectPacket.class, 4, Side.SERVER);
And here are examples of sending data with packets, for strings you'll want to use writeUTF("String"); and readUTF();
I feel it would take a long time to write a large explanation and it would be easier just to give examples. If you have any questions just ask.
Client particle effect: https://github.com/sekwah41/Naruto-Mod/ ... acket.java
Server particle effect: https://github.com/sekwah41/Naruto-Mod/ ... acket.java
Message packet: https://github.com/sekwah41/Naruto-Mod/ ... ssage.java
Client packet handler (I just have all the client packets running code in this file)
https://github.com/sekwah41/Naruto-Mod/ ... ndler.java
Server packet handler(same reason as the client handler)
https://github.com/sekwah41/Naruto-Mod/ ... ndler.java
To send packets
So what I would personally do is make it so it writes the file string to the outputStream e.g. outputStream.writeUTF(fileContents); and then read it on the other side e.g. String fileContents = inputStream.readUTF();
packetNetwork = NetworkRegistry.INSTANCE.newSimpleChannel("SNM");
packetNetwork.registerMessage(ClientParticleEffectPacket.class, ClientParticleEffectPacket.class, 0, Side.CLIENT);
packetNetwork.registerMessage(ServerParticleEffectPacket.class, ServerParticleEffectPacket.class, 4, Side.SERVER);
And here are examples of sending data with packets, for strings you'll want to use writeUTF("String"); and readUTF();
I feel it would take a long time to write a large explanation and it would be easier just to give examples. If you have any questions just ask.
Client particle effect: https://github.com/sekwah41/Naruto-Mod/ ... acket.java
Server particle effect: https://github.com/sekwah41/Naruto-Mod/ ... acket.java
Message packet: https://github.com/sekwah41/Naruto-Mod/ ... ssage.java
Client packet handler (I just have all the client packets running code in this file)
https://github.com/sekwah41/Naruto-Mod/ ... ndler.java
Server packet handler(same reason as the client handler)
https://github.com/sekwah41/Naruto-Mod/ ... ndler.java
To send packets
ByteArrayOutputStream bos = new ByteArrayOutputStream(8);
DataOutputStream outputStream = new DataOutputStream(bos);
try {
outputStream.writeInt(jutsuSound);
outputStream.writeDouble(playerMP.posX);
outputStream.writeDouble(playerMP.posY);
outputStream.writeDouble(playerMP.posZ);
} catch (Exception ex) {
ex.printStackTrace();
}
PacketDispatcher.sendPacketToServer(new ServerSoundPacket(bos.toByteArray()));
or for sending to players
acketDispatcher.sendPacketToPlayer(new ClientJutsuPacket(bos.toByteArray()), playerEntity);
So what I would personally do is make it so it writes the file string to the outputStream e.g. outputStream.writeUTF(fileContents); and then read it on the other side e.g. String fileContents = inputStream.readUTF();