Git Product home page Git Product logo

websocket-challenge's Introduction

Dependency Status

Websocket Challenge

A simple WebSocket competition script for Node.js that uses WebSocket-Node WebSocket server. The challenge is a little contest designed for after-training practice sessions so people can have fun with WebSockets applying their recently acquired knowledge.

Installing and running

  1. Run npm install websocket-challenge or clone this repo
  2. Install dependencies with npm install.
  3. Install CoffeeScript if you don't have it: npm install -g coffee-script
  4. Run tests: npm test
  5. Run server: npm start.

Solving the challenge

WebSocket Challenge message protocol is JSON-based, msg field is used to determine message type.

{ "msg":"message" }

Launch the server script.

Think of a cool team/participant name, establish a WebSocket connection and send a challenge_accepted message:

{ "msg": "challenge_accepted", "name": "Socket Masters" }

The server will respond with

{ "msg":"auth", "auth_token":"12a8d3c1" }

which contains an authentication token which you will attach to your messages so the server can identify your team. A very convenient way of WebSocket debugging is through WebSocket Frames panel in Network tab in Google Chrome developer tools.

There're just two simple tasks:

Task #1

Request Task#1 with

{ "msg": "task_one", "auth_token": token }

The server will respond with

{ "msg": "compute", "operands":operands, "operator": operator };

where operands is a two-element array, e.g [3,7] of numbers no bigger than 9 and operator is a string '+' or '*' or '-' which corresponds to an arithmetic operation you have to perform with the operands. Send the result with

{ "msg": "task_one_result", "result":10, "auth_token": token };

Response is either

{ "msg": "win", "text": "" };

where text contains further instructions on how to request Task #2 (so people don't send Task #2 before Task #1) or an error message. All error messages have msg set to "error" so you can handle them separately or just use the WebSocket Frames panel.

Task #2

When you find out how to request Task #2, the server will send you the following message:

{ "msg": "binary_sum", "bits": 8 };

where bits is either 8 or 16. Immediately after that you should receive a binary message (16 bytes) which you should treat as a Uint8Array or Uint16Array depending on the bits field. Your task is to sum the resulting array's elements and send the result:

{ "msg": "task_two_result", "auth_token": token, "result": 462374 }

After that you should receive a confirmation message (or an error message, which shouldn't make you sad, because you have unlimited attempts) which will end the challenge for you and, should you be the first to solve the tasks, declare you the winner (a message will appear in server console)!

That's all for now, there's plenty of room for improvement and extensions though, so your PRs are very welcome ๐Ÿ˜‰

Contributors (in order of appearance)

Vasiliy Ermolovich
Dzmitry Varabei
Pavel Nosovich

websocket-challenge's People

Contributors

daquirm avatar forcewake avatar nashby avatar tlena avatar

Stargazers

Martin Hollywood avatar Dzmitry Varabei avatar

Watchers

 avatar James Cloos avatar  avatar  avatar

websocket-challenge's Issues

Better logging

Logging format should be improved for the sake of readability and easier parsing/querying.

Live statistics

Create challenge live stats aggregation functionality, back-end endpoint and page view
Perfect for running WSC lives in bars ๐Ÿป

Open challenge mode

Challenge service should be deployment-ready to enable continuous websocket competitions or for demonstration purposes. ๐Ÿ†

Protect assets critical to challenge completion

Make resources that challenge participants should not be able to obtain in any way other than completing the challenge configurable so that they are defined upon challenge start on the server machine (that participants have no access to) or encrypt them to prevent anyone from accessing them directly. This feature will allow to use this repo and all its information for the participants' benefit.

Whoa, that was a long write indeed ๐Ÿ˜…

Wrong assertions in state specs

Throw assertions are written in an ambiguous way so compiler actually creates a wrapper function around method calls which renders the assertions useless, e.g.

-> participant.update_state().should.throw Error

becomes

function() {
        return participant.update_state().should["throw"](Error);
};

which is not quite what's expected ๐Ÿ˜•

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.