GithubHelp home page GithubHelp logo

follower-maze's Introduction

Follower Maze

Some good old TCP socket programming with ruby.

Follower Maze is a TCP server that reads in events from an event source and forwards them onto appropiate user clients.

The server accepts two types of clients:

  • One event source: It will send you a stream of events which may or may not require clients to be notified
  • Many user clients: Each one representing a specific user, these wait for notifications for events which would be relevant to the user they represent

The Protocol

The protocol used by the clients is string-based (i.e. a CRLF control character terminates each message). All strings are encoded in UTF-8.

The event souce connects on port 9090 and will start sending events as soon as the connection is accepted.

The many user clients will connect on port 9099. As soon as the connection is accepted, they will send to the server the ID of the represented user, so that the server knows which events to inform them of. For example, once connected a user client may send down: 2932\r\n, indicating that they are representing user 2932.

After the identification is sent, the user client starts waiting for events to be sent to them. Events coming from event source should be sent to relevant user clients exactly like read, no modification is required or allowed.

The Events

There are five possible events. The table below describe payloads sent by the event source and what they represent:

Payload Sequence # Type From User Id To User Id
666 F 60 50 666
1 U 12 9 1
542532 B 542532 Broadcast -
43 P 32 56 43
634 S 32 634 Status Update

Using the verification program supplied, you will receive exactly 1000 events, with sequence number from 1 to 1000. The events will arrive out of order.

Events may generate notifications for user clients. **If there is a user client ** connected for them, these are the users to be informed for different event types:

  • Follow: Only the To User Id should be notified
  • Unfollow: No clients should be notified
  • Broadcast: All connected user clients should be notified
  • Private Message: Only the To User Id should be notified
  • Status Update: All current followers of the From User ID should be notified

If there are no user client connected for a user, any notifications for them must be silently ignored. user clients expect to be notified of events in the correct order, regardless of the order in which the event source sent them.

Solution

The server is based on an Evented/Reactor pattern allowing it to listen for connections, accept connections, read from and write to both ports all within one process, without the use of threads. The code uses no external libraries or dependencies.

Running the code

The server can be run with the command:

$ rake run_server

The test suite using the JAR file can be run with the command:

$ rake run_test_suite

Tests

A comprehensive set have rspec tests have been written to ensure all the functionality is covered and to verify that all classes are working correctly. The tests can be can be run from the root directory with the following command:

$ rspec spec

follower-maze's People

Contributors

nburkley avatar

Stargazers

 avatar  avatar

Watchers

 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.