hi i am just wondering how would you send a website through a socket as i am trying to make my own web server.

do you just open up the file, read the file and write out to the socket ?

openfile = open(home/username/www/index.html, "r"); 

n = read(openfile,buffer,256); 

n = write(newsock_filedesc,openfile, 256) ;

Recommended Answers

All 4 Replies

Line 6 is wrong, it should be

n = write(newsock_filedesc,buffer, 256) ;

so you do not need to read in the html file ?

so you do not need to read in the html file ?

Line 4 reads the file contents into a buffer and then line 6 writes that buffer into a socket.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.