简体   繁体   English

使用Websockets在两个JAVA Web应用程序之间进行通信

[英]communication between two JAVA web applications using Websockets

I have a java web application (Servlet and JSP based) running on local machine with chat facility using HTML5 and Java WebSocket api. 我有一个Java Web应用程序(基于Servlet和JSP)在本地计算机上运行,​​具有使用HTML5和Java WebSocket api的聊天功能。 One can chat with other user logged in on same application (using two different browsers). 一个人可以与登录同一应用程序的其他用户聊天(使用两个不同的浏览器)。

I have created a replica of same project (web application) and changed the required configuration to run it as a different web-app. 我已经创建了相同项目(Web应用程序)的副本,并更改​​了所需的配置以将其作为其他Web应用程序运行。 What I want is that a user logged-in on ,say web-app1, can chat with user logged-in on web-app2. 我要的是一个登录用户(例如web-app1)可以与登录到web-app2的用户聊天。

Here are the code snippet of ServerEndpoint annotation and JavaScript code to connect to websocket end point 这是ServerEndpoint批注的代码段和连接到Websocket端点的JavaScript代码

@ServerEndpoint(value = "/chat/{sessionId}",
    encoders = ChatMessageCodec.class,
    decoders = ChatMessageCodec.class,
    configurator = ChatEndpoint.EndpointConfigurator.class)

@WebListener
public class ChatEndpoint implements HttpSessionListener
{
 .....

....................... .......................

var server;
try {
      server = new WebSocket('ws://' + window.location.host +'<c:url 
                              value="/chat/${chatSessionId}" />');
      server.binaryType = 'arraybuffer';

     } 
catch(error) {
               modalErrorBody.text(error);
               modalError.modal('show');
               return;
             }

I am new to java web development and this web app is part of the project from book I am following :| 我是Java Web开发的新手,此Web应用程序是我关注的书中的项目的一部分:|

I think you'd be better off using message queues for communications between two or more JVMs. 我认为最好使用消息队列在两个或多个JVM之间进行通信。 WebSocket is not an ideal solution for this kind of tasks WebSocket并非此类任务的理想解决方案

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM