Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/362.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/350.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
用Java Vert.x客户端替换JavaScript SockJS客户端_Javascript_Java_Vert.x_Vertx Verticle_Vertx Eventbus - Fatal编程技术网

用Java Vert.x客户端替换JavaScript SockJS客户端

用Java Vert.x客户端替换JavaScript SockJS客户端,javascript,java,vert.x,vertx-verticle,vertx-eventbus,Javascript,Java,Vert.x,Vertx Verticle,Vertx Eventbus,我有一个java vertx的工作服务器和一个客户机,但在SockJS中,我想用java创建这个客户机,如何将其转换为java: const EB_EVENT_TO_SERVER=“EVENT.TO.SERVER”; const EB_EVENT_TO_CLIENT=“EVENT.TO.CLIENT.”; const EB_EVENT_TO_CLIENTS=“EVENT.TO.CLIENTS”; 让EB_路径; 让eb; 函数initEventBus() { EB_PATH=`${config

我有一个java vertx的工作服务器和一个客户机,但在SockJS中,我想用java创建这个客户机,如何将其转换为java:

const EB_EVENT_TO_SERVER=“EVENT.TO.SERVER”;
const EB_EVENT_TO_CLIENT=“EVENT.TO.CLIENT.”;
const EB_EVENT_TO_CLIENTS=“EVENT.TO.CLIENTS”;
让EB_路径;
让eb;
函数initEventBus()
{
EB_PATH=`${config.host}/${config.folder}/${config.group}/events`;
eb=新事件总线(eb_路径);
eb.onopen=开放式车辆;
}
函数sendEventToServer(消息)
{
发送(eb_事件_到_服务器,消息);
}
函数openEventBus()
{
eb.registerHandler(eb_事件到客户端+播放器ID,(错误,消息)=>onReceiveUnicast(错误,消息));
eb.registerHandler(eb_事件到_客户端,(错误,消息)=>onReceiveBroadcast(错误,消息));
}
函数translateUnicast(json)
{
if(json.hasOwnProperty(“玩家”)和&json.hasOwnProperty(“砖块”))
translateJsonToCanvas(json);
}
函数translateBroadcast(json)
{
}
函数onReceiveUnicast(错误、消息)
{
如果(错误)
错误(“接收单播时,EventBus上出现了错误”);
其他的
translateUnicast(message.body)
}
接收广播功能(错误、消息)
{
如果(错误)
console.error(“接收广播时EventBus上出现了错误”);
其他的
translateBroadcast(message.body)
}
试试看

发送和接收消息的主要代码:

HttpClient-client=vertx.createHttpClient();
websocket(8080,“localhost”,“/someuri”,websocket->{
处理程序(数据->{
System.out.println(“接收数据”+数据转换字符串(“ISO-8859-1”);
client.close();
});
writeBinaryMessage(Buffer.Buffer(“helloworld”);
});