Giter Site home page Giter Site logo

tcp_echoer's Introduction

TCP echoer

Let's try what we've learned with the tokio tutorials. The goal is to have two binaries:

  • A client sends several "words" on the same TcpSender, and listens on it
  • A server listens and echoes each hello asynchronously, with different executing times per task

Run the server first:

cargo run --bin server

And then the client, in a different terminal:

cargo run --bin client

Survey file changes with cargo watch

cargo watch -x 'run --bin client'
cargo watch -x 'run --bin server'

What I want

I want the client to:

  • send all words at once, or well, almost at once, using the same TCP socket, one asynchronous task per word. (or maybe not?)
  • log every send when it happens
  • listens on the same TCP socket

I want the server to:

  • receive all words at once, or well, almost at once,
  • log the receiving of each word, and for each word, spawn a task that:
    • sleeps for a random time between 0 and 2 seconds
    • echoes the word back to the client on the same TCP socket
    • log the sending of each echoed word

All echoing tasks would run simultaneously. This means that within 2 seconds, all words will be echoed in a random order.

Meanwhile, the client:

  • listens on the same TCP connection
  • logs every incoming word

How it's going now

Word sending is synchronous.

The client sends the words all right (does not listen yet), the server receives them (it seems), but when echoing them, the server "hears" them, and re-echoes them, and so on and so on.

tcp_echoer's People

Contributors

keksoj avatar

Watchers

 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.