471,570 Members | 1,305 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,570 software developers and data experts.

making an http server

hi
i am making an http server
it has following functions
main()
{
if option is "-?", output the hints and stop
check the directory supplied is sensible and not a security risk
become a daemon process
ignore child programs (to avoid zombies when child processes stop)

create a socket, bind it to a port number and start listening to the
socket

forever {
wait and accept incoming socket connection
start a new thread
web function
else close new connection
}
}

log()
{
outputs error, sorry or log messages to the nweb.log file
if a sorry message, transmit it to the browser as a fake HTML response
if error or sorry message the program is stopped
}

web() - this function returns the request back to the browser
{
read from the socket the HTTP request
check it's a simple GET command
check no parent directory requested to escape the web servers home
directory
if no file name given assume index.html
check the file extension is valid and supported
check the file is readable by opening it
transmit the HTTP header to the browser
transmit the file contents to the browser
sleep thread for 1 second
stop
}
mine problem is how can i start a new thread for every new request i
recieve
plz help

Nov 30 '05 #1
2 1808
Probably some hints here:
http://www.asp.net/Projects/Cassini/...ndex=0&tabid=1

--
Gregory A. Beamer
MVP; MCP: +I, SE, SD, DBA

***********************************************
Think Outside the Box!
***********************************************
"lucifer" <um**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
hi
i am making an http server
it has following functions
main()
{
if option is "-?", output the hints and stop
check the directory supplied is sensible and not a security risk
become a daemon process
ignore child programs (to avoid zombies when child processes stop)

create a socket, bind it to a port number and start listening to the
socket

forever {
wait and accept incoming socket connection
start a new thread
web function
else close new connection
}
}

log()
{
outputs error, sorry or log messages to the nweb.log file
if a sorry message, transmit it to the browser as a fake HTML response
if error or sorry message the program is stopped
}

web() - this function returns the request back to the browser
{
read from the socket the HTTP request
check it's a simple GET command
check no parent directory requested to escape the web servers home
directory
if no file name given assume index.html
check the file extension is valid and supported
check the file is readable by opening it
transmit the HTTP header to the browser
transmit the file contents to the browser
sleep thread for 1 second
stop
}
mine problem is how can i start a new thread for every new request i
recieve
plz help

Nov 30 '05 #2
Hi,

You can use a sync queue for example, in your main thread (the one
accepting connections) each time a new connection is received the TcpClient
(or Socket) is stored in a Sync'd Queue, a new thread is spawn to execute
the serving methid, this method dequeue the first element from the queue and
it's the sockets it uses
cheers,

--
Ignacio Machin,
ignacio.machin AT dot.state.fl.us
Florida Department Of Transportation

"lucifer" <um**********@gmail.com> wrote in message
news:11**********************@g43g2000cwa.googlegr oups.com...
hi
i am making an http server
it has following functions
main()
{
if option is "-?", output the hints and stop
check the directory supplied is sensible and not a security risk
become a daemon process
ignore child programs (to avoid zombies when child processes stop)

create a socket, bind it to a port number and start listening to the
socket

forever {
wait and accept incoming socket connection
start a new thread
web function
else close new connection
}
}

log()
{
outputs error, sorry or log messages to the nweb.log file
if a sorry message, transmit it to the browser as a fake HTML response
if error or sorry message the program is stopped
}

web() - this function returns the request back to the browser
{
read from the socket the HTTP request
check it's a simple GET command
check no parent directory requested to escape the web servers home
directory
if no file name given assume index.html
check the file extension is valid and supported
check the file is readable by opening it
transmit the HTTP header to the browser
transmit the file contents to the browser
sleep thread for 1 second
stop
}
mine problem is how can i start a new thread for every new request i
recieve
plz help

Nov 30 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Fuzzyman | last post: by
1 post views Thread by Erwin S. Andreasen | last post: by
3 posts views Thread by Mark Adams | last post: by
5 posts views Thread by Paul Mason | last post: by
5 posts views Thread by Charlie | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Vinnie | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.