diff --git a/compilers/json/postalcodes.pir b/compilers/json/postalcodes.pir index d047169..b4337dd 100755 --- a/compilers/json/postalcodes.pir +++ b/compilers/json/postalcodes.pir @@ -27,19 +27,20 @@ places with that code from around the world. postal = argv[1] - .local pmc sock - .local string address, buf, json_result + .local pmc sock, address + .local string buf, json_result json_result = '' .local int ret .local int len # create the socket handle - socket sock, 2, 1, 0 + sock = new 'Socket' + sock.'socket'(2, 1, 0) unless sock goto ERR # Pack a sockaddr_in structure with IP and port - sockaddr address, 80, 'ws.geonames.org' - connect ret, sock, address + address = sock.'sockaddr'('ws.geonames.org', 80) + sock.'connect'(address) .local string url url = 'http://ws.geonames.org/postalCodeSearchJSON?maxRows=10&postalcode=' @@ -48,11 +49,12 @@ places with that code from around the world. $S0 = 'GET ' $S0 .= url $S0 .= " HTTP/1.0\nUser-agent: Parrot\n\n" - send ret, sock, $S0 - poll ret, sock, 1, 5, 0 + sock.'send'($S0) + #poll ret, sock, 1, 5, 0 MORE: - recv ret, sock, buf - if ret < 0 goto END + buf = sock.'recv'() + ret = length buf + if ret <= 0 goto END json_result .= buf goto MORE ERR: