forked from parrot/parrot
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Sample to grab a home page through HTTP.
git-svn-id: https://svn.parrot.org/parrot/trunk@4680 d31e2699-5ff4-0310-a27c-f18f2fbe73fe
- Loading branch information
Melvin Smith
committed
Oct 30, 2003
1 parent
8613509
commit afc15cb
Showing
1 changed file
with
37 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# http client, connects to WWW port and grabs a page. | ||
# Be sure to set PARROT_NET_DEVEL to 1 in io/io_private.h | ||
# and rebuld Parrot or the network layer won't exist | ||
|
||
.sub _main | ||
.local pmc sock | ||
.local string address | ||
.local string buf | ||
.local int ret | ||
.local int len | ||
print "Creating socket.\n" | ||
# create the socket handle | ||
socket sock, 2, 1, 0 | ||
unless sock goto ERR | ||
# Pack a sockaddr_in structure with IP and port | ||
#sockaddr address, 80, "129.42.18.99" | ||
sockaddr address, 80, "www.ibm.com" | ||
print "Connecting to http://www.parrotcode.org:80\n" | ||
connect ret, sock, address | ||
print "connect returned " | ||
print ret | ||
print "\n" | ||
send ret, sock, "GET /us/ HTTP/1.0\nUser-agent: Parrot\n\n" | ||
poll ret, sock, 1, 5, 0 | ||
MORE: | ||
recv ret, sock, buf | ||
if ret < 0 goto END | ||
print buf | ||
goto MORE | ||
ERR: | ||
print "Socket error\n" | ||
end | ||
END: | ||
close sock | ||
end | ||
.end | ||
|