-
Notifications
You must be signed in to change notification settings - Fork 138
/
http.pir
67 lines (50 loc) · 1.26 KB
/
http.pir
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# Copyright (C) 2001-2008, Parrot Foundation.
=head1 NAME
examples/io/http.pir - HTTP client
=head1 SYNOPSIS
% ./parrot examples/io/http.pir
=head1 DESCRIPTION
HTTP client, connects to WWW port and grabs a page (L<http://www.ibm.com>).
You should be running the echo service on your box (port 7).
=cut
.include 'socket.pasm'
.sub example :main
.local pmc sock
.local pmc address
.local string buf
.local int ret
.local int len
# create the socket handle
print "Creating socket.\n"
sock = new 'Socket'
sock.'socket'(.PIO_PF_INET, .PIO_SOCK_STREAM, .PIO_PROTO_TCP)
unless sock goto ERR
# Pack a sockaddr_in structure with IP and port
address = sock.'sockaddr'("www.ibm.com", 80)
print "Connecting to http://www.ibm.com:80\n"
ret = sock.'connect'(address)
print "connect returned "
print ret
print "\n"
ret = sock.'send'("GET /us/en/ HTTP/1.0\r\nUser-agent: Parrot\r\n\r\n")
MORE:
buf = sock.'recv'()
ret = length buf
if ret <= 0 goto END
print buf
goto MORE
ERR:
print "Socket error\n"
end
END:
sock.'close'()
end
.end
=head1 SEE ALSO
F<io/io_private.h>.
=cut
# Local Variables:
# mode: pir
# fill-column: 100
# End:
# vim: expandtab shiftwidth=4 ft=pir: