You are not logged in.
Last year for our OS class, a friend and I wrote a simple multithreaded server that communicated with a client to send and receive data over a TCP/IP network. We implemented a brief ad-hoc protocol to actually send data, but as part of the requirements we had to build a threading/networking that was shared between the server and client. In our model the server creates a separate thread for each client whenever it gets a new connection. I have the idea of taking our code and reshaping it into a server library -- it handles the basic socket networking stuff and spins off a new thread for each connection. 1 thread-per-client might not be very efficient for a normal HTTP server that's getting lots of different clients, but it could be good for a connection that's going to last a long time. Can you guys give me some examples for where long-term connections are popular and if such a library could be useful?
Thanks,
Basu
The Bytebaker -- Computer science is not a science and it's not about computers
Check out my open source software at Github
Offline
Comet/websocket web apps, xmpp, irc... there are lots of things that use long lived connections.
As to one-thread-per-client, you may run into issues with long lived connections that communicate rarely (such as chat). You may want to use a thread pool, and async io (epoll/poll/kqeue) watches on client sockets -- wake up on io availability, and use a thread to handle the processing. It would be far more work to do it that way though, so in some cases threading alone gets you what you need (few clients that are all doings lots of communication).
"Be conservative in what you send; be liberal in what you accept." -- Postel's Law
"tacos" -- Cactus' Law
"t̥͍͎̪̪͗a̴̻̩͈͚ͨc̠o̩̙͈ͫͅs͙͎̙͊ ͔͇̫̜t͎̳̀a̜̞̗ͩc̗͍͚o̲̯̿s̖̣̤̙͌ ̖̜̈ț̰̫͓ạ̪͖̳c̲͎͕̰̯̃̈o͉ͅs̪ͪ ̜̻̖̜͕" -- -̖͚̫̙̓-̺̠͇ͤ̃ ̜̪̜ͯZ͔̗̭̞ͪA̝͈̙͖̩L͉̠̺͓G̙̞̦͖O̳̗͍
Offline