async-std/docs/src/tutorial/specification.md
CosciaDiPollo 9ad0cf9f80 Correct a typo on the async-std version (#508)
Correct a typo on the async-std version in the Cargo.toml file of the documentation.
2019-11-11 21:14:55 +01:00

1.3 KiB

Specification and Getting Started

Specification

The chat uses a simple text protocol over TCP. The protocol consists of utf-8 messages, separated by \n.

The client connects to the server and sends login as a first line. After that, the client can send messages to other clients using the following syntax:

login1, login2, ... loginN: message

Each of the specified clients then receives a from login: message message.

A possible session might look like this

On Alice's computer:   |   On Bob's computer:

> alice                |   > bob
> bob: hello               < from alice: hello
                       |   > alice, bob: hi!
                           < from bob: hi!
< from bob: hi!        |

The main challenge for the chat server is keeping track of many concurrent connections. The main challenge for the chat client is managing concurrent outgoing messages, incoming messages and user's typing.

Getting Started

Let's create a new Cargo project:

$ cargo new a-chat
$ cd a-chat

At the moment async-std requires Rust nightly, so let's add a rustup override for convenience:

$ rustup override add nightly
$ rustc --version
rustc 1.38.0-nightly (c4715198b 2019-08-05)

Add the following lines to Cargo.toml:

[dependencies]
futures = "0.3.0"
async-std = "1.0.0"