Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add WebSockets example #592

Closed
jaguililla opened this issue Jan 3, 2022 · 11 comments
Closed

Add WebSockets example #592

jaguililla opened this issue Jan 3, 2022 · 11 comments
Assignees
Labels
good first issue Earn your wings at the OSS community help wanted

Comments

@jaguililla
Copy link
Member

jaguililla commented Jan 3, 2022

I.e.: https://javalin.io/tutorials/websocket-example

@jaguililla jaguililla transferred this issue from hexagontk/tfb Jan 5, 2023
@jaguililla jaguililla added the good first issue Earn your wings at the OSS community label Jan 5, 2023
@jaguililla jaguililla changed the title Check worthy examples to implement Add WebSockets example Jun 1, 2023
@abhishekabk5
Copy link
Contributor

Hi, I would like to contribute here,
In what way should I add the example? as a ReadMe file or a Template or something else?

@jaguililla
Copy link
Member Author

Hello, and thanks for collaborating with this project! I've just created a repository to contain the example, you can fork it, implement the example, and file the PR there, this is the URL: https://github.com/hexagonkt/websockets_chat

Please note that web sockets is not the best tested part of the toolkit, if you find any problem, please tell me (or even better, file a bug 😉).

Thanks again and... Happy coding!

@jaguililla jaguililla moved this from Ready to In Progress in Hexagon Jul 21, 2023
@abhishekabk5
Copy link
Contributor

@abhishekabk5
Copy link
Contributor

abhishekabk5 commented Jul 25, 2023

Facing an issue here, not sure why

Image

As per postman docs, the response code should be 101 (switching protocols) and not 202 (accepted), and i believe that's why connection is not being established. But I don't have much experience in WebSockets
Ref - https://youtu.be/H-7EZVj9D-k

@jaguililla
Copy link
Member Author

Right now I'm not at home. Let me get back to you regarding this issue after Sunday 30th :)

However, please use the http_server_netty adapter (changing the dependency in the gradle.build.kts file) as the Jetty adapter don't support WS yet.

I'll create a different task to explicitly fail when you try to use a feature not supported by the chosen adapter, but right now it fails silently :(

@abhishekabk5
Copy link
Contributor

Ok, got it. i'll try with that and let you know the progress

@abhishekabk5
Copy link
Contributor

Great, it's working fine now. Now, to make a sample webpage for this.

@abhishekabk5
Copy link
Contributor

I have added the sample page as well. Complete task PR: hexagontk/websockets_chat#1

@jaguililla
Copy link
Member Author

Thank you for your contribution!

It would be great if the HTML page was served from the server (and connecting to http://localhost:9090 take you to the chat's page). That could be done easily by moving the page to the resources and serving those static resources (there are examples on the documentation).

I'll merge it right now as it is, if you want to code the proposed changes you can file another PR. Thanks!

@jaguililla jaguililla moved this from In Progress to Done in Hexagon Jul 29, 2023
@abhishekabk5
Copy link
Contributor

Hey, Great to see my PR merged!
I would like to make the proposed changes. But I tried moving the page to the resources folder, but it didn't work, http://localhost:9090 still shows up as 404. I must be missing something, Which example are you referring to?
Draft PR: hexagontk/websockets_chat#2

@jaguililla
Copy link
Member Author

Sorry I though I had an example with that functionality :(

Here is the example code to serve a classpath directory over a resource: https://github.com/hexagonkt/hexagon/blob/develop/http/http_test/src/main/kotlin/com/hexagonkt/http/test/examples/FilesTest.kt#L56

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Earn your wings at the OSS community help wanted
Projects
Archived in project
Development

No branches or pull requests

2 participants