slawlor / ractor

Rust actor framework
MIT License
1.3k stars 66 forks source link

Request for TCP Echo Server Example with TcpListener and TcpStream as Actors #207

Closed simon-fu closed 4 months ago

simon-fu commented 4 months ago

Hello,

I am very interested in ractor and hope to use it to write some network service programs. However, I haven’t seen any relevant examples. I believe there are many people with similar ideas to mine. I hope to add a TCP echo server example to the project to help more people get started with ractor quickly.

Here is a more detailed description of the desired functionality:

  1. The TcpListener should be an actor that listens for incoming TCP connections.

  2. For each new connection, a new child actor should be created. This actor will handle the TcpStream for that connection.

  3. The child actor should read data from the TcpStream and write the exact same data back to the TcpStream.

I believe this example would be a valuable addition to the examples provided in the Ractor documentation, as it would demonstrate how to use Ractor to handle multiple concurrent TCP connections in an efficient and scalable manner.

Thank you for considering this request.

slawlor commented 4 months ago

This is the wrong project for this request. A TCP actor, while present in ractor_cluster is specific to the cluster formation. We have an associated crate, ractor_actors which has a collection of generic TCP actors where this would be a better fit. However the way we've generated the TCP actor there is assuming length-prepended messages, which won't really fit for an echo server which say takes human input.

Some modification would be necessary, but this issue is better targeted in that repository. Thanks.