2020-11-15 23:54:47 +03:00
|
|
|
import net
|
|
|
|
import io
|
2020-08-21 00:01:37 +03:00
|
|
|
|
2020-12-15 18:39:11 +03:00
|
|
|
fn main() {
|
|
|
|
// Make a new connection
|
2021-01-26 17:43:10 +03:00
|
|
|
mut conn := net.dial_tcp('google.com:80') ?
|
|
|
|
defer {
|
2021-03-19 10:49:26 +03:00
|
|
|
conn.close() or {}
|
2021-01-26 17:43:10 +03:00
|
|
|
}
|
2021-06-13 23:53:38 +03:00
|
|
|
|
2022-04-19 13:29:53 +03:00
|
|
|
println(' peer: ${conn.peer_addr() ?}')
|
|
|
|
println('local: ${conn.addr() ?}')
|
2021-06-13 23:53:38 +03:00
|
|
|
|
2020-12-15 18:39:11 +03:00
|
|
|
// Simple http HEAD request for a file
|
2021-03-19 10:49:26 +03:00
|
|
|
conn.write_string('HEAD /index.html HTTP/1.0\r\n\r\n') ?
|
2020-12-15 18:39:11 +03:00
|
|
|
// Read all the data that is waiting
|
2021-01-26 17:43:10 +03:00
|
|
|
result := io.read_all(reader: conn) ?
|
2020-12-15 18:39:11 +03:00
|
|
|
// Cast to string and print result
|
|
|
|
println(result.bytestr())
|
|
|
|
}
|