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

[SPIKE] Implement WebSockets #1

Closed
2 tasks done
Marcamillian opened this issue Jan 31, 2024 · 5 comments
Closed
2 tasks done

[SPIKE] Implement WebSockets #1

Marcamillian opened this issue Jan 31, 2024 · 5 comments

Comments

@Marcamillian
Copy link
Owner

Marcamillian commented Jan 31, 2024

Aim

Set up a basic WebSocket implementation that can be built upon to create the way we update clients of the gameState.

Steps

  • There is a tutorial here
    • This tutorial uses the gorilla implementation that we are avoiding (Due to issue seen when running Gorilla/mux)
    • Alternative package - golang developed one here

Acceptance Criteria

  • A websocket connection created between client & server
  • Triggered server events send messages back the client
@Marcamillian Marcamillian moved this to Backlog in Skull and Roses: Go Jan 31, 2024
@Marcamillian Marcamillian moved this from Backlog to Ready in Skull and Roses: Go Jan 31, 2024
@Marcamillian Marcamillian moved this from Ready to In progress in Skull and Roses: Go Feb 1, 2024
@Marcamillian
Copy link
Owner Author

Marcamillian commented Feb 1, 2024

When deciding what websocket package to use there were several options

  • github.com/gorilla/websocket
    • As we has issues using gorilla/mux I decided against this
  • golang.org/x/net/websocket
    • In the README.md they suggested using a more maintained package nhooyr.io/websocket
    • Published: 8th Jan 2024
    • Imported by: 5594
    • This post here (from 2016) suggests against using this package in favour of gorilla
  • nhooyr.io/websocket
    • Published: 25th Oct 2023
    • Imported by: 820
    • Seems to be the suggested version
    • Github
      • 3.3k stars

@Marcamillian
Copy link
Owner Author

Progress

Got the Websocket running

  • The websocket is running at /ws/echo
  • A static page served at /static/websocketDemo.html
    • Creates a connection to the websocket endpoint
    • An input sends a message to the websocket
    • The server responds

Improvements

  • Connecting through POSTMAN doesn't work at the moment - gets a 403 error
    • Likely need to adjust the origin settings on the server and set an Origin header in the request detailed here
  • Handle sessions - to allow for reconnection after a disconnect
    • This could be a package or building something myself

@Marcamillian Marcamillian moved this from In progress to In review in Skull and Roses: Go Feb 1, 2024
@Marcamillian Marcamillian moved this from In review to In progress in Skull and Roses: Go Feb 3, 2024
@Marcamillian
Copy link
Owner Author

Progress

Looking into implementing nhooyr.io/weboscket

There is a chat example detailed here

@Marcamillian
Copy link
Owner Author

Progress

I haven't had a huge amount of time to spend on development in the last few weeks (due to being consumed with job applications)

Stuff I have been working on locally is

  • Trying out different websocket libraries
    • gorilla/websocket
    • golang.org/x/net/websocket
    • github.com/lxzan/gws
    • github.com/lxzan/gws
  • Generally echo servers work well
    • I'm missing something when trying to implement the chat examples
    • getting the 403 errors mentioned before

Routes forward

@Marcamillian
Copy link
Owner Author

Feature implemented and Merged in MR #6

@github-project-automation github-project-automation bot moved this from In progress to Done in Skull and Roses: Go Feb 20, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
Status: Done
Development

When branches are created from issues, their pull requests are automatically linked.

1 participant