Unix Programming - Newb Q: Server prog reqd to send files, how?

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > March 2004 > Newb Q: Server prog reqd to send files, how?





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author Newb Q: Server prog reqd to send files, how?
Sal

2004-03-13, 4:33 am

Hi all,

Just hoping somone could point in the right direction. Have just started
learning to program sockets and have programmed both a client and server to
send and recieve messages, but now need to develop a web server to deliver a
web page. Obviously the server program would not have to change much, but to
send a file rather than a message, and I am using a browser as the client.
Any suggestions to what I should be looking at to enable the ability to grab
the file and deliver it??

TIA


GVK

2004-03-13, 6:33 am

Sal wrote:
> Hi all,
>
> Just hoping somone could point in the right direction. Have just started
> learning to program sockets and have programmed both a client and server to
> send and recieve messages, but now need to develop a web server to deliver a
> web page. Obviously the server program would not have to change much, but to
> send a file rather than a message, and I am using a browser as the client.
> Any suggestions to what I should be looking at to enable the ability to grab
> the file and deliver it??
>
> TIA
>
>

Hi,
You can use a while() loop to send a file - line by line. Something like

while(fgets(line,1024,fp) != NULL)
{
write(sockfd,line,strlen(line));
// anything else you want to do
}

I coded one such web server-client application in PERL. Hope the same works in C.

regards,
GVK

--
Happy Hacking!!!
GVK

2004-03-13, 6:33 am

GVK wrote:[color=darkred]
> Sal wrote:
>
Forgot to add, see sendfile(2)

GVK
--
Happy Hacking!!!
Marc Rochkind

2004-03-13, 11:34 am

"Sal" <sallas@dodo.com.au> wrote in message
news:4052ce82$0$22524$5a62ac22@freenews.iinet.net.au...
> Hi all,
>
> Just hoping somone could point in the right direction. Have just started
> learning to program sockets and have programmed both a client and server

to
> send and recieve messages, but now need to develop a web server to deliver

a
> web page. Obviously the server program would not have to change much, but

to
> send a file rather than a message, and I am using a browser as the client.
> Any suggestions to what I should be looking at to enable the ability to

grab
> the file and deliver it??
>
> TIA
>
>


By definition, a Web server implements the server side of HTTP, which is
specified by RFC ("Request for Comments") 2616, which you can read here:

http://www.w3.org/Protocols/rfc2616/rfc2616.html

There's a simple example of a Web server here:

http://basepath.com/aup/ex/group__AUP2ex.html

(Look in the examples for Chap. 8)

--
Marc Rochkind
"Advanced UNIX Programming" (publishing April 2004)
www.basepath.com/aup


sal

2004-03-20, 10:33 pm


"Marc Rochkind" <rochkind@basepath.com> wrote in message
news:FZednRwPX-lasc7dRVn-iQ@speakeasy.net...
> "Sal" <sallas@dodo.com.au> wrote in message
> news:4052ce82$0$22524$5a62ac22@freenews.iinet.net.au...
> to
deliver[color=darkred]
> a
but[color=darkred]
> to
client.[color=darkred]
> grab
>
> By definition, a Web server implements the server side of HTTP, which is
> specified by RFC ("Request for Comments") 2616, which you can read here:
>
> http://www.w3.org/Protocols/rfc2616/rfc2616.html
>
> There's a simple example of a Web server here:
>
> http://basepath.com/aup/ex/group__AUP2ex.html
>
> (Look in the examples for Chap. 8)
>
> --
> Marc Rochkind
> "Advanced UNIX Programming" (publishing April 2004)
> www.basepath.com/aup
>
>

Thanks all, what I really needed was to use:

file = fopen("homepage.html","r");
fread((void*)buffer,1,1023,file);
write(CS_sock,buffer,strlen(buffer));

(with other error code).


Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com