T
T
tzendos2015-10-19 01:23:27
Computer networks
tzendos, 2015-10-19 01:23:27

Rust, writing a chat server, how to be?

Good afternoon.
I got interested in server programming in Rust, found a small example:
https://github.com/Hoverbear/rust-rosetta/blob/mas...
Yes, everything is clear and cool. But I wanted more, namely a full-fledged chat server. (In the spirit of pure Rust and the use of its native functions). Then I will finish the client in another higher-level language (C#, Java).
The idea is the same, run a separate thread for a separate client, where the socket will listen and send messages. But how to be? How to run this thread correctly so that after receiving a message, send this message to all other users? Naturally, users need to be stored, let's say temporarily: in Vec, or in HashMap. But how do you access this shared socket listing from functions running on a thread?
I will be glad to have a working example to analyze it further.
Thanks in advance.

Answer the question

In order to leave comments, you need to log in

1 answer(s)
S
Sergey, 2015-10-19
Protko @Fesor

give up the idea of ​​creating per user thread, this is far from the most efficient way to work with I / O. Better arm yourself with an event loop.
https://nbaksalyar.github.io/2015/07/10/writing-ch...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question