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

server-spinach: pinging, registration, moves #5

Merged
merged 3 commits into from
Sep 6, 2014
Merged

Conversation

hlian
Copy link
Contributor

@hlian hlian commented Sep 5, 2014

This is essentially Basilica's sockets with a few tricks from my sleeve:

  • Recursion with runMaybeT . forever instead of a tail call
  • Exception handling -- websockets is insensibly terrible 1 2 at handling exceptions, and the best way to work around it is to catch and finagle them ourselves
  • Separation of models and state: I wanted Player and Move to be independent of the rest of the application, so Connection objects are directly stored in the DB. This allows for a slight simplification of the heartbeat, which becomes a fancy filterM

Because GHCI doesn't fork to run main, you'll have to keep kill $(lsof -i :9160 | tail -n 1 | tr -s ' ' | cut -d ' ' -s -f 2)-ing in order to make it let go of the port. I recorded a little Emacs macro with C-( and C-) to do it for me, but I think it's easier to just have iTerm open and use cabal run.

I also had another tab open with cabal repl for :load Client, cmain.

* Pinging/ponging
* GCing
* Player registration
* Moving

Example (with ponging off):

*Client> forM_ [cmain, cmain, cmain] forkIO
*Client> + Sending {"email": "ThreadId 282"}
+ Sending {"player": {"email": "ThreadId 282"}, "x": 1.0, "y": 1.0}
+ Sending {"player": {"email": "ThreadId 282"}, "x": 0.0, "y": 0.0}
+ Sending {"email": "ThreadId 283"}
+ Sending {"player": {"email": "ThreadId 283"}, "x": 1.0, "y": 1.0}
+ Sending {"player": {"email": "ThreadId 283"}, "x": 0.0, "y": 0.0}
+ Sending {"email": "ThreadId 284"}
+ Sending {"player": {"email": "ThreadId 284"}, "x": 1.0, "y": 1.0}
+ Sending {"player": {"email": "ThreadId 284"}, "x": 0.0, "y": 0.0}
+ Pinged: "{\"ping\": true}"
+ Ponged
+ Pinged: "{\"ping\": true}"
+ Ponged
+ Pinged: "{\"ping\": true}"
+ Ponged
ghc: ConnectionClosed
ghc: ConnectionClosed
+ Pinged: "{\"ping\": true}"
+ Ponged
ghc: ConnectionClosed
+ Sending {"player": {"email": "ThreadId 283"}, "x": 0.5, "y": 0.5}
+ Sending {"player": {"email": "ThreadId 282"}, "x": 0.5, "y": 0.5}
+ Sending {"player": {"email": "ThreadId 283"}, "x": 0.7, "y": 0.7}
+ Sending {"player": {"email": "ThreadId 282"}, "x": 0.7, "y": 0.7}
+ Good night
+ Good night
+ Sending {"player": {"email": "ThreadId 284"}, "x": 0.5, "y": 0.5}
+ Sending {"player": {"email": "ThreadId 284"}, "x": 0.7, "y": 0.7}
+ Good night
@ianthehenry
Copy link
Contributor

i love it

ianthehenry added a commit that referenced this pull request Sep 6, 2014
server-spinach: pinging, registration, moves
@ianthehenry ianthehenry merged commit dabb994 into master Sep 6, 2014
@hlian hlian deleted the server-spinach branch September 7, 2014 04:57
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants