01 WinSock Demo

            needs sock.f

create tbuf 256 allot

: sdump ( sock -- )

  begin

    dup sock-read? if dup tbuf 256 rot sock-read tbuf swap type then

    dup sock-closed? key? or until

  sock-close drop ;

s" www.jiemang.com" 80 sock-open value sock

crlf$ count sock sock-write .                   

s" GET / HTTP/1.1" sock sock-write .

crlf$ count sock sock-write .

s" Host: www.jiemang.com" sock sock-write .

crlf$ count sock sock-write .

s" Connection: keep-alive" sock sock-write .

crlf$ count sock sock-write .

s" Cache-Control: max-age=0" sock sock-write .

crlf$ count sock sock-write .

s" Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8" sock sock-write .

crlf$ count sock sock-write .

s" Upgrade-Insecure-Requests: 1" sock sock-write .

crlf$ count sock sock-write .

s" User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/46.0.2490.86 Safari/537.36" sock sock-write .

crlf$ count sock sock-write .

\ s" Accept-Encoding: gzip, deflate, sdch" sock sock-write .

\ crlf$ count sock sock-write .

s" Accept-Language: zh-TW,zh;q=0.8,en-US;q=0.6,en;q=0.4" sock sock-write .

crlf$ count sock sock-write .

crlf$ count sock sock-write .

crlf$ count sock sock-write .

cr sock sdump