This post was hidden

I want this to be hidden so i hide it, it's nothing special just dont want this post to be with my account.

We prefer markdown to images on this forum:

```
code goes here
```

And you should see it in the preview pane like

use std::io::{Write, Read};
fn main() {
   println!("etc, etc");
}

First things first: Did you build/run your code with --release?

I can't think of anything that would make the program particularly faster. Network time is going to dominate anything specific to your code. If you're going to be making multiple requests, and especially multiple concurrent requests, you're probably going to want a client library that implements connection pools, async, and keep-alive, like reqwest. Or if you don't need async, perhaps ureq.

2 Likes

Make sure you add --release flag when you build or run it. The default is to run in debug mode which can be 50 times slower.

read_to_string reads everything it can, so it has to wait until the connection is closed. This will make your program wait for the other side to disconnect. Network protocols usually specify a length of bytes to read or some terminator character to read a fixed number of bytes without waiting for disconnection. You will need to design your network protocol and change the sending side, or use an existing protocol like HTTP.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.