what i have so far -

void do_handleclient(int connsock,struct sockaddr_in *client_addr) {
  // Communicating with our new friend.
  string buffer, execmd, filename;
  int b, n, nstr, str;
  char buf[25000];
  char *cbuff=(char*)buf.c_str();

  while((n=recv(connsock,buf,25000-1,0))!=0)  //receiving request.
	  buffer[n]=0;
  while(buffer[nstr]!=' ') {                                   
//pulling GET or POST command out of request.
	  execmd[nstr]=buffer[nstr];
	  nstr++;
  }
  while(buffer[nstr]!='\r' || buffer[nstr]!=' ') {    
 //pulling filename out of rest 
	  filename[str]=buffer[str];
	  nstr++;
  }
  
  fd=open(filename,O_RDONLY);//opening the textfile
  int rbytes;
  while(1) {
      rbytes=read(fd,buf,25000); // Reading the textfile.
      if(rbytes=0)               // EOF.
	      break;
  //    if(send(connsock,buf,rbytes,0)==-1)    
//send like this maybe?
  //        break;
  }

  int needed = buf.length();                                   
  while (needed) {  //or like this?
	  int n=write(connsock, cbuff, needed);
	  cbuff+=n;
  }
}

I just don't know how to go about sending the client the requested file. I believe I've got the concatenation to get the command and filename out of a sample request ("GET sample1.html") but I'm just not sure how to take the determined filename and get the contents of that file and put them into the socket stream. Thanks in advance

Edited 7 Years Ago by GPXtC02: n/a

u are doing it in the correct direction.
Go ahead with your code and test it.
May be (not sure) u need to break up your file into smaller blocks for transferring if the file is very large.

This article has been dead for over six months. Start a new discussion instead.