Public | Automated Build

Last pushed: a year ago
Short Description
UDP server that listens to port 55355 responds with JSON
Full Description

#Description#

This is an UDP server that listens to port 55355 and responds with a JSON formatted output via stdout.
The program is expecting the text to be formatted like:
[DD/MM/YYYY HH:MM] MESSAGE BODY

And the answer is formmated like:
{"timestamp":<DATE OF MESSAGE IN EPOCH>,"message":<MESSAGE BODY>}

If the message received by the server is not properly formatted, it responds to the sender with an error.

#Usage#

This can be either run directly by executing ./udpserver.rb or it can be dockerized.
Check the instructions for details.

Assumptions:

  • For simplicity, port 55355/udp is expected to be available.

  • You are using either Linux or OSX.

#Instructions#

Local environment setup:

1) Clone this repo

2) Open a console and cd to ./sre-challenge

3) Run ./udpserver.rb

Note: You need to have ruby 2.1 (or greater) installed in your system.

4) In another console, send a message to the server by running:

$ echo -n '[28/07/2016 10:30] Finish up this README.md!' | nc -uw 1 localhost 55355

5) Check the console where the server is running, you will see this output:

Program listening to UDP port 55355. Press Control-C to stop it {"timestamp":"1469701800","message":"Finish up this README.md!"}

Docker environment setup:

I'm assuming that you already sorted out your docker installation/configuration.

Please refer to https://docs.docker.com/engine/installation/ if you don't have docker yet installed in your machine.

1) Clone this repo

2) Open a console and cd to ./sre-challenge

3) Run docker run -ti -p 55355:55355/udp hunterchris/sre-challenge

Now read carefully as the next steps vary depending on your platform

If you are using Linux

4a) Open another console and send a message to the server by running:

  $ echo -n '[28/07/2016 10:30] Finish up this README.md!' | nc -uw 1 localhost 55355

5a) Check the console where the server is running, you will see this output:

  Program listening to UDP port 55355. Press Control-C to stop it
  {"timestamp":"1469701800","message":"Finish up this README.md!"}

If you are using OSX

4b) Connect to the docker-machine, if you did the default installation you can do so by running:

docker-machine ssh default, that will give you a prompt into the boot2docker VM

5b) From that console, send a message to the server by running:

  $ echo -n '[28/07/2016 10:30] Finish up this README.md!' | nc -uw 1 localhost 55355

6b) Check the console where the server is running, you will see this output:

 Program listening to UDP port 55355. Press Control-C to stop it
 {"timestamp":"1469701800","message":"Finish up this README.md!"}

Why the difference? Because docker doesn't run natively in OSX; instead, it creates a VM that acts as the docker host...

When you run docker run -ti -p 55355:55355 hunterchris/sre-challenge, you are telling docker to expose port 55355/udp
from the container to port 55355/udp in the docker host. You will not see any output outside your docker host.

Questions? Don't hesitate to throw me an email

Cool bonus: This repo is configured with an auto-build to dockerhub, it means that every time I push to master, it automatically triggers a docker build to update the image with the latest changes, you can check that out here:
https://hub.docker.com/r/hunterchris/sre-challenge/

Docker Pull Command
Owner
hunterchris
Source Repository

Comments (0)