EarthScope / ringserver

Apache License 2.0
30 stars 16 forks source link

Websocket connection on dedicated ListenPort #41

Closed stefanmaar closed 1 year ago

stefanmaar commented 1 year ago

Hello.

I tried to initiate a Websocket connection to a ringserver running on localhost using seisplotjs. The seisplotjs application was also running on localhost. Within seisplotjs I tried to connect to the ringserver using the URL ws://localhost:16000/datalink.

I couldn't connect to the ringserver and the ringserver issued the error message:

Wed Mar 08 10:44:28 2023 - Client connected [16000]: 127.0.0.1 [127.0.0.1] port 59254
Wed Mar 08 10:44:28 2023 - [127.0.0.1] Cannot determine allowed client from 'GET' 

The ringserver was configured with dedicated ports for each protocol:

ListenPort 18000 SeedLink
ListenPort 16000 DataLink
ListenPort 8080 HTTP 

After changing the port configuration to a single port

ListenPort 16000

, the websocket connection worked as expected using the URL ws://localhost:16000/datalink.

crotwell commented 1 year ago

I think if you had tried ws://localhost:8080/datalink it may have worked. By using only DataLink in ListenPort 16000 DataLink you are effectively saying do not allow DataLink over web sockets on port 16000, only raw DataLink sockets. Using ListenPort 8080 HTTP says allow web socket DataLink and SeedLink, but not the raw socket versions.

I do not know if it is possible to have HTTP connections without allowing web socket DataLink/SeedLink or with only one.

stefanmaar commented 1 year ago

I have tried the ws://localhost:8080/datalink URL in the beginning. ringserver refused the connection saying that it can't handle datalink websocket request on non-DataLink port.

crotwell commented 1 year ago

Ah ok. A web socket must be created by an upgrade command on an existing http connection and so you can't do a websocket datalink without HTTP. That is in the web socket spec, so out of ringserver's control. Suggest if you want web socket datalink without seedlink that you use ListenPort 16000 DataLink HTTP, or just ListenPort 16000 if you want to allow both protocols over both types of sockets.

chad-earthscope commented 1 year ago

As @crotwell writes, WebSocket requires a combination of both HTTP and SeedLink or DataLink to be enabled. There is no special mode to enable just WebSocket, if there were it would simply be a shortcut combination of protocols, with no way to deny non-WebSocket connections.