Reputation: 93
I am new to Rust, and I am writing a library that creates background threads that listen and handle TCP communications. I want to store the latest n
bytes for every TCP client and have Python to be able to fetch them. The way I am thinking about this is to have shared buffers, although I am not sure how to achieve that given Rust's memory model.
This is what I want to achieve at the end:
import tcp_server_pyo3
# How can I return something that would keep track of TCP connections?
listener = tcp_server_pyo3.start("127.0.0.1:6142")
# So I could print all the TCP clients that are currently connected
print(listener.connections())
# And this would return the latest n bytes received for the "client_id"
listener.read("client_id")
Below is what I have so far. It's currently able to create a listener and connection handler threads. What should I add/change to be able to keep track of connections and read latest bytes that were communicated from Python?
I am not sure if I am thinking about this the right way. I though of global variables but people are saying not to use global variables in Rust.
Upvotes: 1
Views: 211