본문내용
izeof(serv_addr))<0 ) {
perror("connect to WEB server error!!!"); return -1;
}
/* make newURL and send it to WEB server */
if( !nextflag )
sprintf( buf, "%s %s %s \n%s\n\n", method, newURL, HTTPver, buf2 );
else
sprintf( buf, "%s %s %s \n%s", method, newURL, HTTPver, buf2 );
if( write( servsd, buf, strlen(buf) ) < 0 ) {
perror("request newURL to WEB server Error!!!"); return -1;
};
printf( "=======> SND to WEB = [%s]\n", buf ); /**/
if( nextflag ) { /* more to read : NETSCAPE */
if( (rc = read(clisd, buf, sizeof(buf)-1)) <= 0 ) {
perror("read error from BROWSER !!!"); close(servsd); return -1;
}
buf[rc] = 0;
printf( "from BROWSER 2 == %d[%s]\n", rc, buf );
fflush(stdout); /**/
if( write( servsd, buf, rc ) < 0 ) {
perror("send POST data to WEB server Error!!!"); return -1;
};
printf( "=======> SND2 to WEB = [%s]\n", buf ); /**/
}
/*서버에게 요청을 보냈으니 이제는 서버의 응답을 읽어 브라우저로 보내야한다*/
printf("------ Send response to BROWSER .... --------\n");
toClient( servsd, clisd );
return 0;
}
int toClient( servsd, clisd )
int servsd;
int clisd;
{
int i;
int rc=1;
char buf[4096+1];
while( rc > 0 ) {
if( (rc = read(servsd, buf, sizeof(buf)-1)) <= 0 ) {
perror("connection closeed from WEB server!!!\n");
close(servsd);
close(clisd);
return -1;
}
buf[rc] = 0;
printf( "from WEB == %d[%.60s]\n", rc, buf );
fflush(stdout); /**/
if( write( clisd, buf, rc ) < 0 ) {
perror("-----Send to BROWSER Error!!!---------");
};
printf("-----After Send to BROWSER !!! [%.60s]---------\n", buf);
fflush(stdout); /**/
}
}
perror("connect to WEB server error!!!"); return -1;
}
/* make newURL and send it to WEB server */
if( !nextflag )
sprintf( buf, "%s %s %s \n%s\n\n", method, newURL, HTTPver, buf2 );
else
sprintf( buf, "%s %s %s \n%s", method, newURL, HTTPver, buf2 );
if( write( servsd, buf, strlen(buf) ) < 0 ) {
perror("request newURL to WEB server Error!!!"); return -1;
};
printf( "=======> SND to WEB = [%s]\n", buf ); /**/
if( nextflag ) { /* more to read : NETSCAPE */
if( (rc = read(clisd, buf, sizeof(buf)-1)) <= 0 ) {
perror("read error from BROWSER !!!"); close(servsd); return -1;
}
buf[rc] = 0;
printf( "from BROWSER 2 == %d[%s]\n", rc, buf );
fflush(stdout); /**/
if( write( servsd, buf, rc ) < 0 ) {
perror("send POST data to WEB server Error!!!"); return -1;
};
printf( "=======> SND2 to WEB = [%s]\n", buf ); /**/
}
/*서버에게 요청을 보냈으니 이제는 서버의 응답을 읽어 브라우저로 보내야한다*/
printf("------ Send response to BROWSER .... --------\n");
toClient( servsd, clisd );
return 0;
}
int toClient( servsd, clisd )
int servsd;
int clisd;
{
int i;
int rc=1;
char buf[4096+1];
while( rc > 0 ) {
if( (rc = read(servsd, buf, sizeof(buf)-1)) <= 0 ) {
perror("connection closeed from WEB server!!!\n");
close(servsd);
close(clisd);
return -1;
}
buf[rc] = 0;
printf( "from WEB == %d[%.60s]\n", rc, buf );
fflush(stdout); /**/
if( write( clisd, buf, rc ) < 0 ) {
perror("-----Send to BROWSER Error!!!---------");
};
printf("-----After Send to BROWSER !!! [%.60s]---------\n", buf);
fflush(stdout); /**/
}
}