babl icon indicating copy to clipboard operation
babl copied to clipboard

How to create websocket server endpoints?

Open ccnlui opened this issue 3 years ago • 2 comments

How would you implement a server endpoint?

For example, client would connect to ws://localhost:8080/myendpoint, instead of just ws://localhost:8080.

I assumed I'd have to implement this function myself inside onSessionConnected, but the Session object doesn't seem to provide any information on the client's request, I was hoping to be able to get the request's path/endpoint/query etc...

How can this be done?

Thank you.

ccnlui avatar Jun 09 '22 01:06 ccnlui

Hi @ccnlui babl will accept web-socket connections to any URI on the port. So your client should be able to connect to

ws://localhost:8080/myendpoint

or indeed

ws://localhost:8080/anything_else_you_like

however, the URI part of the request is not parsed or surfaced by the library in any way.

Header parsing is done in KeyDecoder, which would be a reasonable place to detect/assign the request URI:

https://github.com/babl-ws/babl/blob/b09f52f10ae90e562b70b9983fee55e87803659e/src/main/java/com/aitusoftware/babl/websocket/KeyDecoder.java#L59

I would consider a PR that added the request URI to the session object.

epickrram avatar Jun 09 '22 07:06 epickrram

Here's my attempt: https://github.com/babl-ws/babl/pull/122 I'd appreciate any feeback.

ccnlui avatar Aug 17 '22 21:08 ccnlui