Jump to content
  • Advertisement
Sign in to follow this  
Basiror

HTTP Webserver with TCP

This topic is 4867 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi I had a look at the HTTP protocol lately and found it really easy to use but I have a few questions regarding TCP and HTTP The first question is about how to handle incoming connections on the server: 1. Create a socket with IN_ADDR_ANY and your poirt 2. create a listen queue with listen(.....) 3. accept connections here s my concern, accept opens a new socket for the connection attempt I can use this socket to communicate with the client, fine but if there are 1000s of clients connecting to a single server I d get 1000s of open sockets, isn t this a little bad performance wise? How should i proceed? keep the connection alive til the client disconnects or if the socket returned by accept times out? Or should i close the socket immediately after I have done everything? I guess the first one because you need to wait for incoming packets so can I set the puffer size of such a socket? and make it nonblocking? otherwise I had to mess around with multithreading which isn t really what I am keen on at the moment any idea?

Share this post


Link to post
Share on other sites
Advertisement
Quote:
Original post by Basiror
I can use this socket to communicate with the client, fine
but if there are 1000s of clients connecting to a single server I d get 1000s of open sockets, isn t this a little bad performance wise?


Not really. A socket as seen by your program is just a reference into the system's IP stack, and most of those are optimized pretty well.

Quote:

How should i proceed?
keep the connection alive til the client disconnects or if the socket returned by accept times out?

Or should i close the socket immediately after I have done everything?

That depends on the protocol you're using. Originally, HTTP was designed to use a simple open-request-close scheme, but there is the possibility of persistant connection. Have a look at the relevant RFCs to see how that is determined.

Quote:

so can I set the puffer size of such a socket? and make it nonblocking?
otherwise I had to mess around with multithreading which isn t really what I am keen on at the moment

Setting the buffer (window) size is possible on some systems and impossible or restricted on others. For most applications, you should not need to worry about that. Non-blocking I/O on sockets is generally possible. Have a look at select() for "easily" managing a number connections from a single thread.

Share this post


Link to post
Share on other sites
ok I had a look at select

the following questions arises


i create a fd_set

add the sockets i want to check to the set with the FD_makros

ok fine

then pass the fd_sets to the select call

the call returns and those sockets that can read write ... are still in the
SOCKET array of the fd_set and those who couldn t be read are set to zero

is this correct?

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!