-
Notifications
You must be signed in to change notification settings - Fork 120
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Trying to understand asynchronous client. #53
Comments
I also believe there is an issue with sync::tcp::connect not closing the socket correctly. I have the following code that eventually fails with too many open files error.
|
For everyone encountering this issue: |
I can't figure out how to make let mut context = tokio_modbus::client::tcp::connect("127.0.0.1:502".parse()?).await?;
let (a, b) = tokio::join!(
context.read_holding_registers(1, 1),
context.read_holding_registers(2, 1),
);
context.disconnect().await?;
dbg!(a, b); I've tried to create a context for every request but a server doesn't like this. I thought about to wrap context in |
Because pretty much everything is uses Internal state is mutated when making any networking request, reading from a For concurrent writes to the same server you would need two contexts but many devices can't handle parallel requests correctly. Hope that helps. |
I consider the issue to be resolved. |
Hi I am having trouble understanding how or the best way to make many requests in a multi threaded way.
Basically I was trying to simulate talking to a couple of thousand modbus devices as quickly as possible. As I don't have those devices :) I was running your tcp-server.rs example with added delays of 60-80 ms. This seems reasonable as a simulation.
My trouble is developing the client code.
I want all the requests to be asynchronous. Once they all complete I would store these results into a db.
Would you recommend running code like
in many threads and having each result send back through a channel ? or is there a better way built in using tokio async ?
Thanks
The text was updated successfully, but these errors were encountered: