/*******************************************************************************
        active.c
        Z-World, 2000

        A simple demonstration of a TCP/IP session, by retriving a
        web page from a remote site.
*******************************************************************************/

#define MY_IP_ADDRESS	"10.10.6.101"
#define MY_NETMASK		"255.255.255.0"
#define MY_GATEWAY		"10.10.6.19"
#define MY_NAMESERVER	"10.10.6.1"

#define WEBSITE 			"www.zweng.com"
#define FILE				"/"
#define PORT	 			80

#memmap xmem
#use "dcrtcp.lib"

main()
{
	int status;
	tcp_Socket s;
	char buffer[2048];
	longword ip;
	
	sock_init();
	
	ip=resolve(WEBSITE);
	tcp_open(&s,0,ip,PORT,NULL);
	sock_wait_established(&s,0,NULL,&status);
	
	sock_mode(&s,TCP_MODE_ASCII);
	
	sprintf(buffer,"GET %s\r\n",FILE);
	sock_puts(&s,buffer);
		
	while(tcp_tick(&s)) {
		sock_wait_input(&s,0,NULL,&status);
		if(sock_gets(&s,buffer,2048))
			printf("%s\n",buffer);
	}

	return 0;
	
sock_err:
	switch(status) {
		case 1: /* foreign host closed */
			printf("User closed session\n");
			break;
				
		case -1: /* timeout */
			printf("\nConnection timed out\n");
			break;
	}
}