method TcpStream.write
Writes all of data.
Example:
use std.net { SocketAddr, TcpListener, TcpStream, IpAddr }
fn main() -> () | NetError | ParseError io, net {
let l = TcpListener.bind(SocketAddr.parse("127.0.0.1:0")?)?
defer l.close()?
let c = TcpStream.connect(l.local, 2s)?
defer c.close()?
let s = l.accept(3s)?
defer s.close()?
c.write(b"\x01\x02\x03")?
print("{s.read(16)?}")
}Вывод
b"\x01\x02\x03"
pub(api) fn write(buf: bytes, timeout: Duration? = none) -> () | NetError netСложность. O(n) in the size of the buffer.
С версии. 1.0.0-beta
Параметры
| Имя | Тип |
|---|---|
buf | bytes |
timeout | Duration? = none |
Возвращает
()
Ошибки
NetError- `Timeout`, `Unavailable` (the peer closed the connection), `Cancelled`.
Эффекты
net
Определено в: std/net/net.oxl:610