java - RandomAccessFile 不适用于 Minecraft Forge
问题描述
我目前正在为 Minecraft 开发一个 Mod,它有一个用 C++ 和 Qt5 编写的专用 Gui 系统。我让我的 GUI 和 Minecraft 通过命名管道进行通信,但我有一个小问题。我可以用一个简单的 Java 和 C++(Qt) 程序在管道中读写。但是当我在 Minecraft Forge 的初始化后创建我的 Pipeendpoint 类的新实例时,它无法从管道中读取任何内容。在独立系统中,它可以读取内容。
不工作 Forge 实施:
package de.CoderDE.CodersAnimationEditor;
import java.io.FileNotFoundException;
import de.CoderDE.CodersAnimationEditor.Pipe.PipeEndpoint;
import net.minecraft.client.Minecraft;
import net.minecraftforge.fml.client.registry.ClientRegistry;
import net.minecraftforge.fml.common.event.FMLInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPostInitializationEvent;
import net.minecraftforge.fml.common.event.FMLPreInitializationEvent;
import net.minecraftforge.fml.relauncher.Side;
import net.minecraftforge.fml.relauncher.SideOnly;
@SideOnly(Side.CLIENT)
public class ClientProxy extends CommonProxy {
static PipeEndpoint pendpoint;
@Override
public void preInit(FMLPreInitializationEvent e) {
super.preInit(e);
}
@Override
public void init(FMLInitializationEvent e) {
super.init(e);
}
@Override
public void postInit(FMLPostInitializationEvent e) {
super.postInit(e);
try {
pendpoint = new PipeEndpoint();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e1) {
e1.printStackTrace();
}
}
}
工作独立实施:
import java.io.FileNotFoundException;
import de.CoderDE.CodersAnimationEditor.Pipe.PipeEndpoint;
public class Main {
static PipeEndpoint pipe;
public static void main(String[] args) {
try {
pipe = new PipeEndpoint();
} catch (FileNotFoundException e1) {
e1.printStackTrace();
}
try {
Thread.sleep(10000);
} catch (InterruptedException e) {
e.printStackTrace();
}
}
}
还有重要的 PipeEndpoint 类:
package de.CoderDE.CodersAnimationEditor.Pipe;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.RandomAccessFile;
public class PipeEndpoint {
private Thread reciever;
private RandomAccessFile pipe;
public PipeEndpoint() throws FileNotFoundException {
pipe = new RandomAccessFile("\\\\.\\pipe\\CodersAnimationEditor", "rw");
reciever = new Thread(new PipeEndpointReciever());
reciever.start();
}
private class PipeEndpointReciever implements Runnable {
@Override
public void run() {
try {
while (true) {
System.out.print((char)pipe.read());
}
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
而“无法读取任何内容”我的意思是它永远不会从 pipe.read() 返回。哦,Java 应用程序在 C++(Qt) LocalServer 开始侦听并等待新连接之后启动。
解决方案
推荐阅读
- kotlin - Ktor 响应 outputStream 导致 io.netty.handler.timeout.WriteTimeoutException
- python - 如何创建 python 脚本来运行 jenkins 作业?
- android - 未来
' 不是类型 'Stream 的子类型 - >
- c# - C# 使用正则表达式以正确的单元格格式读取 CSV 数据
- ruby-on-rails - 调试从 Vue.js 提取数据的 Rails 模型
- javascript - Vis JS Timeline - 垂直滚动时冻结水平时间轴
- python - Selenium 不会按类名找到我的元素(Python)
- python - Python:合并两个字典并设置默认值
- c++ - 了解不相关类型的用户定义转换
- java - 我不确定为什么代码不会输出任何语句。当我在我的 IDE 中运行它时,没有任何输出