简体   繁体   中英

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. 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. What I want is that a user logged-in on ,say web-app1, can chat with user logged-in on web-app2.

Here are the code snippet of ServerEndpoint annotation and JavaScript code to connect to websocket end point

@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 :|

I think you'd be better off using message queues for communications between two or more JVMs. WebSocket is not an ideal solution for this kind of tasks

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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