i got two question here:
Question 1:
i got the following code:
while (1) {
printf("\nftp> ");
scanf("%s",buf); //read command
send(sd,buf,strlen(buf),0);
if(strcmp(buf,"list")==0){ //if command is 'list'
printf("Obtaining file list server...");
n = recv(sd,buf,sizeof(buf),0); //get list of file from server
write(1,buf,n);
}
}
the output is unexpected, which is:
ftp>list
file1
file2
Obtaining file list from server...
ftp>
by right i should get something like:
ftp>list
Obtaining file list from server...
file1
file2
ftp>
isn't it? anyone help me?
Question 2:
I'm developing a webserver, below are part of my code...
while(1){
alen = sizeof(cad);
if((sd2=accept(sd,(struct sockaddr *)&cad, &alen)) < 0){
printf("accept failed\n");
exit(1);
}
n = recv(sd2, buf, sizeof(buf), 0);
sscanf(buf,"%s%s", request,pathname); // extract GET and filename
printf("%s",request);
printf("%s",pathname);
if(!fpt=fopen(pathname,"r"){
sprintf(buf,"<html><h1>Error 404</h1></html>
send(1,buf,strlen(buf),0);
}
else{
printf(buf,"<html><h1>Hello World</h1></html>");
send(1,buf,strlen(buf),0);
}
closesocket(sd2);
}
the problem:
1.
printf("%s",request);
printf("%s",pathname);
this two lines never been executed... (coz no output)
2.
when there is no such file on the path.. the program just stop and quit... it will never gonna print out the Error 404 page...
however, it works in the else part.. which display hello world..
anyone?
thanks