我在 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";
let EB_PATH;
let eb;
function initEventBus()
{
EB_PATH = `${config.host}/${config.folder}/${config.group}/events`;
eb = new EventBus(EB_PATH);
eb.onopen = openEventBus;
}
function sendEventToServer(message)
{
eb.send(EB_EVENT_TO_SERVER, message);
}
function openEventBus()
{
eb.registerHandler(EB_EVENT_TO_CLIENT + playerId, (error, message) => onReceiveUnicast(error, message));
eb.registerHandler(EB_EVENT_TO_CLIENTS, (error, message) => onReceiveBroadcast(error, message));
}
function translateUnicast(json)
{
if (json.hasOwnProperty("players") && json.hasOwnProperty("bricks"))
translateJsonToCanvas(json);
}
function translateBroadcast(json)
{
}
function onReceiveUnicast(error, message)
{
if (error)
console.error("Something went wrong on the EventBus while receiving Unicast");
else
translateUnicast(message.body)
}
function onReceiveBroadcast(error, message)
{
if (error)
console.error("Something went wrong on the EventBus while receiving Broadcast");
else
translateBroadcast(message.body)
}
我正在寻找的主要是vertx客户端连接到我的vertx服务器的基本启动代码