Re: making an http server

Tech-Archive recommends: Fix windows errors by optimizing your registry



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" <umeshktangnu@xxxxxxxxx> wrote in message
news:1133369609.498812.314330@xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx
> 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
>


.



Relevant Pages

  • Re: Storing data from multiple clients
    ... I could also have each callback create a connection object, open it, use it ... internal FIFO buffer which would be filled by the socket ... long queue of unstored data builds up (which would mean the DB can't handle ... public void Initialize() ...
    (microsoft.public.dotnet.framework.adonet)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #3]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... kernel socket family. ... presentation side is left to the client. ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • MULTITHREADED
    ... where each client request are handle ... connected socket return by accept function. ... X Server close the connection without passing all the requested data ...
    (comp.programming.threads)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)
  • [PATCH 0/5] [RFC] AF_RXRPC socket family implementation [try #2]
    ... These patches together supply secure client-side RxRPC connectivity as a Linux ... Make it possible for the client socket to be used to go to more than one ... Each connection goes to a particular "service". ...
    (Linux-Kernel)