简体   繁体   中英

Establish websocket communication between two Tomcats

I'm learning websockets. What I have done is established a websocket connection with Tomcat as server endpoint and for client side I have used JavaScript. Everything is fine.

What I want to know is if it is possible to have another Tomcat container as client endpoint? If so how can it be established? Or is it possible to use servlet or REST endpoint as client endpoint like:

@webservlet("/sampleservlet")
@clientendpoint

or

@requestmapping("/hello")
@clientend

A websocket could be programmatically established between one webserver and another. There are two scenarios that I can think of for your "server liveness" problem.

  1. The monitoring webserver could have a background thread (ie not associated with any client request) that uses (say) the Apache HTTPComponents libraries to establish a websocket connection to the monitored service.

  2. The monitoring webserver could actually tunnel a connection from the user's browser to the monitored service.

I don't think these are particularly good ideas (especially the second one). A better idea would be to use ordinary requests to do the liveness monitoring. (If you use websockets, there is a risk that your monitoring will mislead; eg if the monitored service stops accepting new requests.)

Another idea would be to use JMX, or plain sockets to implement the monitoring.

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