Code Monkey home page Code Monkey logo

translator's Introduction

Overview

This project implements a "translator", which takes JSON arguments from Websocket client, reformat it into SCGI and forward it to rTorrent, waiting response from rTorrent and then pass the response to the websocket client.

There are two main concepts in the project, websocket connection and scgi connection. The former works as a "server" to wait for websocket client to connect and takes the JSON message from the client, and then pass the message to the latter. The latter takes the JSON message, wrapped it into scgi format and then send to rTorrent, send the response from rTorrent to websocket connection, which send it to the websocket client. As the saying goes, "Any problem in computer science can be solved by another layer of indirection", websocket connection is such an "another layer of indirection".

Class Design & Data Flow

There are specific comments in the code, straightforward to understand, class design overview is shown below:

Class Design

The following picture shows the process of data flow

Data Flow

Dependency

uWebsockets is used in this project to implement "Websocket Connection", so you must make uWebsockets and its dependency(uSockets, openssl, zlib, etc) ready in your dev machine. Noted that wss (websockets with ssl) are used here so you have to compile uWebsockets with ssl option (WITH_OPENSSL=1 make). You can take a look at my blog if you have problem on compiling and install uWebsockets and uSockets.

Build

The project can build with CMake easily

git clone https://github.com/Young-Flash/translator.git

cd translator

mkdir build && cd build

cmake ..

make

./translator

Run

You can use Postman as websocket client to access the "Websocket Connection" and send JSON message to it easily.

Alt Text

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.