-
Notifications
You must be signed in to change notification settings - Fork 342
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
How to read TCP? #1054
Comments
Is the written byte slice the response to TCP client? |
TCP streams implement the |
I sent the 2nd question below the question of how to read. |
Assuming you have a stream already: use async_std::prelude::*;
let mut bytes = [0u8; 32];
stream.read(&mut bytes).await?; Replace |
If I write b"hello world" to incoming TCP stream then use flush method for TCP stream, the browser tells me invalid HTTP response. |
What's the difference between .read_to_end() and .poll_read()? .poll_read_vectored() and .poll_write_vectored() allows using multiple buffers, what's the use case of multiple buffers? @notgull |
@notgull My program binded to address 127.0.0.1:1024, I used my browser to connect to this address, the content read from the stream was: |
This is because you're writing raw text instead of a valid HTTP response. You would need to write something like
The main draw of vectored reads and writes is that it allows you to have multiple buffers split across memory for your read operation. An example use case would be in HTTP, if you wanted to read the header to one buffer and the body to another. See this page for more information. |
If I don't write anything at that time, the web browser may tell me socks not connected. Can it tell web browsers to wait for responses (maybe wait for 5 minutes) instead of showing error like socks not connected? |
I have the same problems! // read and ignored
let mut buffer = [0; 1024];
stream.read(&mut buffer).await; |
This example only shows to write a byte slice to stream, but how to read from the stream?
The text was updated successfully, but these errors were encountered: