10575

What Uri path to use to connect to Spring WebSocket

Question:

I have a WebSocket Application using Spring MVC that I have defined as per <a href="https://spring.io/blog/2013/05/23/spring-framework-4-0-m1-websocket-support" rel="nofollow">this</a> tutorial. The file that configures the WebSocket is the following:

package com.myapp.spring.web.controller; import java.io.IOException; import javax.websocket.OnClose; import javax.websocket.OnError; import javax.websocket.OnMessage; import javax.websocket.OnOpen; import javax.websocket.Session; import javax.websocket.server.ServerEndpoint; import org.springframework.web.socket.server.standard.SpringConfigurator; @ServerEndpoint(value="/serverendpoint", configurator = SpringConfigurator.class) public class serverendpoint { @OnOpen public void handleOpen () { System.out.println("JAVA: Client is now connected..."); } @OnMessage public String handleMessage (Session session, String message) throws IOException { if (message.equals("ping")) { // return "pong" session.getBasicRemote().sendText("pong"); } else if (message.equals("close")) { handleClose(); return null; } System.out.println("JAVA: Received from client: "+ message); MyClass mc = new MyClass(message); String res = mc.action(); session.getBasicRemote().sendText(res); return res; } @OnClose public void handleClose() { System.out.println("JAVA: Client is now disconnected..."); } @OnError public void handleError (Throwable t) { t.printStackTrace(); } }

My Question is if I have a Javascript client trying to connect to this WebSocket, what Uri should I use if the WebSocket is mapped at "/serverendpoint" as seen from the above @serverendpoint annotation?

var wsUri = "??????" var webSocket = new WebSocket(wsUri);

<strong><em>What should wsUri be?</em></strong>

Here is my Spring MVC project hierarchy:

<a href="https://i.stack.imgur.com/AxLzq.png" rel="nofollow"><img alt="enter image description here" class="b-lazy" data-src="https://i.stack.imgur.com/AxLzq.png" data-original="https://i.stack.imgur.com/AxLzq.png" src="https://etrip.eimg.top/images/2019/05/07/timg.gif" /></a>

Answer1:

It is the same address for your server running the http port

Recommend

  • Connecting from .NET to Asterisk
  • Got 404 error on tomcat 7.0.47 websocket
  • Viewpager sound not synchronised with image
  • Clear content in xml brackets in all files in directory tree on Windows using Strawberry Perl and tw
  • apache tomcat 8 websocket origin and client address
  • Is there any provision in android to know which user application is using which system service
  • Cursor inside Trigger not working
  • How to make two-way data binding between service and controller
  • What Connection is this?
  • Create Google Calendar events from a Google Spreadsheet - script is creating duplicates
  • Why in a test class that extends AndroidTestCase, does getContext() return null?
  • https://websocket not connect android
  • playing sound with google script
  • Webworker-threads in NodeJS
  • Why am I recieving a JMSBytesMessage when I'm sending an OBject message using Spring and MQ Que
  • Connecting to Azure ServiceBus Queue
  • Pointing EF to a database when the POCO files are in a seperate project
  • Facebook Profile.getCurrentProfile() is always returns null after the first login
  • Convert a plain string[] into a Observable and concat it to another Observable using RxJS 5
  • Websocket across pages JavaScript
  • indexedDB doesn't reset version when you delete a database on Chrome — bug or user error?
  • Getting Javascript Errors From Another Window
  • jQuery UI .sortable() call is slow when applies to thousands of elements
  • How to send an std::vector of unsigned char over an UDP socket using boost asio?
  • How to read data from socket connection - android
  • Insert null in a database
  • Cannot send user message with Spring Websocket
  • Spring @Transactional - javax.persistence.TransactionRequiredException
  • What is the likely cause of a net::ERR_CONNECTION_ABORTED when uploading a file to Spring
  • Error in making a socket connection
  • How to use carriage return with multiple line?
  • Read a local file using javascript
  • ImageMagick, replace semi-transparent white with opaque white
  • Control modification in presentation layer
  • Cannot connect to cassandra from Spark
  • How to recover from a Spring Social ExpiredAuthorizationException
  • Cross-Platform Protobuf Serialization
  • Adding custom controls to a full screen movie
  • Alternatives to the OPTIONAL fallback SPARQL pattern?
  • Confusion with PayPal's monthly billing cycle