/*

- Scores Online Test -

Use with Apache,Php,Mysql ..


this too run , with variables, please try:
http://localhost/myspace/index.php?mivar=100&mivar2=4561

Authors:
   * Tristan
   * Pixel

*/

import "net.dll"

PRIVATE
        char msg[512];
        char r[24];
        int handle;
        salida=false;


begin
  set_mode(640,480);

	full_screen=false;
 	net_init();
 	net_resolvehost(0,"www.google.com",80);
 	net_tcp_open(0);

 	//create scores.txt in my disK
  handle = fopen("scores.txt", O_WRITE);

  //build string request :
  msg = "GET http://www.google.com/ HTTP/1.0"
      + chr(13) + chr(10) +
      "Accept: */*" + chr(13) + chr(10) +
      "User-Agent: TBrow01" +
      chr(13) + chr(10) +
      chr(13) + chr(10);

  write(0,0,0,0,"Bytes received(aprox):");
  write_int(0,160,0,0,&x);
  frame;

  //send request to server
 	net_tcp_send(0,&msg,120);

  repeat
    if (net_tcp_recv(0,&r,25)>0) //receive packets 25K
       fwrite(handle,r);
       r="";
       x+=25;
    else
       salida=true;//file download OK
    end

    frame;
  until(key(_esc) or salida)

  fclose(handle);
	net_tcp_close(0);
 	net_quit();

end
