v / examples / buf_reader.v
19 lines · 18 sloc · 488 bytes · 017ace6ea7402430a992aa0820d5e472ebca74c7
Raw
1// Simple raw HTTP head request
2import net
3import time
4import io
5
6fn main() {
7 // Make a new connection
8 mut conn := net.dial_tcp('google.com:80')!
9 // Simple http HEAD request for a file
10 conn.write_string('GET /index.html HTTP/1.0\r\n\r\n')!
11 // Wrap in a buffered reader
12 mut r := io.new_buffered_reader(reader: conn)
13 for {
14 l := r.read_line() or { break }
15 println('${l}')
16 // Make it nice and obvious that we are doing this line by line
17 time.sleep(100 * time.millisecond)
18 }
19}
20