2

Using Spring 4 I need configure WebSocket use other port than HTTP. In other words by default user access to HTTP and WebSocket as follow:

http://server:9090/
ws://server:9090/

But I need do the follow:

http://server:9090/
ws://server:9999/

In code I have only following:

@Configuration
@EnableWebSocket
public class WebSocketConfig
    implements WebSocketConfigurer { 

Also I have Handler:

Handler extends TextWebSocketHandler {

Is there such ability in Spring?

Dewfy
  • 23,277
  • 13
  • 73
  • 121

2 Answers2

3

AFAIK all current implementations of websockets depend on a handshake via HTTP. After the handshake the existing connection is upgraded. You don't get a new one and the port stays the same. Basically all websocket connections start as HTTP connections.

As a side note the ports, IP addresses etc. are subject of the server, not the application itself.

It might be possible to configure your server so that two ports can be used for an application, but they would both be used for HTTP and websocket alike. On the other hand this might be useful in your situation.

a better oliver
  • 26,330
  • 2
  • 58
  • 66
0

Spring WebSocket different port for ws:// protocol

Due to limitation and in order to use websockets on App Engine Flexible Environment, app need to connect directly to application instance using the instance's public external IP. This IP can be obtained from the metadata server.

All MVC/Rest (http://) call should still serve from 8080 and in App Engine Flexible Environment ws:// server from ws://external_ip:65080

working code

https://github.com/kevendra/springmvc-websocket-sample

http://localhost:8080/
ws://localhost:8080/

to work with App Engine need below

http://localhost:8080/
ws://localhost:65080/  - in local
ws://external_ip:65080/ - App engine

Ref:

Extends org.eclipse.jetty.websocket.server.WebSocketHandler and start server context to 65080, but I'm looking for server managed by spring

deamon
  • 89,107
  • 111
  • 320
  • 448
Kevendra
  • 71
  • 1
  • 5
  • Hi. I also have a requirement to run all the APIs on port 8080 and ws:// on 8000. I believe you are able to do this but I am not able to understand from your code that how were you able to achieve this. Could you please explain the basic concept behind your implementation? – BiJ Jun 14 '17 at 06:13