Giter Club home page Giter Club logo

multi-ipc-test's Introduction

multi-ipc-test

This test Rust project is an experiment utilizing Servo’s ipc-channel crate. It features two programs, a server which is meant to be run once, and a client which can be run multiple times. This architecture may be used to send tasks a service during its runtime.

The server creates an IpcOneShotServer instance and provides its name which is passed to the client as a command line argument. The client reads standard input and sends the read data to the specified server together with an IpcSender to provide a callback channel. As the server is one-shot, it is consumed upon accepting the input; it is replaced with a different server, with a different name (which is sent back to the client via the IpcSender). The next client connects to that address, sends its input, receives the new server’s name and so on.

This is an experiment and, as an implementation of the single server/multiple client architecture, is quite crude and probably not optimal. Any suggestions of alternative implementations are welcome.

Usage

This instruction assumes you are using a Unix-like shell. Cargo’s diagnostic messages are omitted. The server names may be different.

Run the server binary in a console or terminal, such as by using cargo run --bin server. The server will print the first name to connect to:

$ cargo run --bin server
<...>
Server name is /tmp/.tmpZ3eONd/socket

Run the client binary in a second terminal or console. Specify the server name printed by server as its command line argument. The client will read data from standard input until reaching end of line; you can pipe the output of any program or contents of any file. The client will send the message and receive the new server’s address:

$ echo 'Hello, world!' | cargo run --bin client /tmp/.tmpZ3eONd/socket
<...>
Packet successfully sent to /tmp/.tmpZ3eONd/socket
New server name: /tmp/.tmpS9E61v/socket

The server will print Hello, world!.

Each new execution of client must use the server name provided by the previous client:

$ echo 'Hello fellow Rustaceans!' | cargo run --bin client /tmp/.tmpS9E61v/socket
<...>
Packet successfully sent to /tmp/.tmpS9E61v/socket
New server name: /tmp/.tmpPBlkPy/socket

Attempts to use an old address will very likely result in a panic.

To shut down the server, pass quit as the second argument. The client will still read data from standard input:

$ echo | cargo run --bin client /tmp/.tmpPBlkPy/socket stop
<...>
Packet successfully sent to /tmp/.tmpPBlkPy/socket
Server is shutting down. Goodbye fellow Rustaceans!

License

As an experiment not intended for practical use, this project is placed into public domain according to terms of the Unlicense.

multi-ipc-test's People

Contributors

babylonas avatar

Stargazers

Dmitrii Vasilev avatar

Watchers

James Cloos 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.