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