Giter Site home page Giter Site logo

browserquest's Introduction

BrowserQuest in Kotlin / SparkJava

I follow a number of technologies one of which is PhaserJS. I saw an article that used PhaserJS and WebSockets (NodeJS/SocketIO) to implement (as a technical demo) an MMORPG in the browser.

The original article can be found here -> http://www.dynetisgames.com/2017/03/06/how-to-make-a-multiplayer-online-game-with-phaser-socket-io-and-node-js/

Having recently got into Kotlin, wanting to experiment with WebSockets and also being a fan of the SparkJava framework, I set about trying to implement the same functionality, but replacing the NodeJS backend with Kotlin and SparkJava. This repository is the working version of my experiment.

Main Changes / Lessons

The main elements that were changed from the original article are

  1. NodeJS serverside was replaced with Kotlin and Spark. This was reasonably easy.
  2. I implemented the serverside in base WebSockets (not SocketIO), so I had to reimplement the Client object in standard WebSockets, to remove the SocketIO code. I also had to play around with the JSON data that got sent back and forth to send message type and message data.
  3. OnWebSocketClosed serverside caused a bit of a problem. I copied the Java version of the SparkJava WebSocket example as the template for the Kotlin serverside. This worked fine for OnWebSocketConnect and OnWebSocketMessage. However, in the OnWebSocketClosed signature, the reason parameter is optional and therefore nullable. A simple change to the signature to allow null was all that was needed.
  4. Kotlin WHEN clause makes the handling of different message types clean and easily understandable.

Licence

Apache 2.0 Licence

Copyright © Wayne Ellis 2017

browserquest's People

Contributors

codemwnci avatar

Stargazers

Ben Gamble avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.