![]() |
| | #1 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Server Program Advice So, I have a few options (I think), I'm wondering what would be the best way to accomplish this task: Assign a large static array of sockets and threads and hope the connections don't go over? Use a dynamic data structure for the array of sockets and threads? If so, what data structure? Another thing: Is there a limit on the amount of sockets for a machine running Windows and a machine running a Unix based distro? Oh and is there a limit for the amount of threads running at any one time? Thanks!
__________________ Quote:
| |
| pobri19 is offline | |
| | #2 | |
| CSharpener Join Date: Oct 2006
Posts: 5,336
| Quote:
think about using selct approach which will processseveral connections. If you want to split work among several CPUs - build a thread pool, select number of threads based on number of CPUs available, and assign new connection to the thread from the pool wich has least number of active connections. the datastructure for storing sockets info will depend on how ofter you need to search for individual members, and what will be the key for the search
__________________ If I have eight hours for cutting wood, I spend six sharpening my axe. | |
| vart is offline | |
| | #3 | |
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Well, each connection will only be made for a short period (anywhere from around 1-10 seconds), and I'm expecting about 1 connection request ever 5-60 seconds. There will probably only be 1 CPU running on this server though, unless I can manage to afford a server with more CPUs (which I doubt - therefore it's probably best just to program it for 1). Edit: Oh and an index of some sort would work fine for a key. So... Any suggestions?
__________________ Quote:
Last edited by pobri19; 03-21-2009 at 04:46 AM. | |
| pobri19 is offline | |
| | #4 |
| Malum in se Join Date: Apr 2007
Posts: 3,188
| Well, per thread works best if you dynamicalyl allocate teh socket object, then pass a pointer to that object to the thread on creation. So you have a listening thread which spawns the actual communication threads. Be aware though that thread per connection will have an effective limit of around 100 connections, after that you start spending too much time switching between threads. A socket pool is a better approach at that point, and spawn only as many communication threads as you have processors, or perhaps one less if you have several. This way the listener thread can just pu tnew connections into the pool, while the communication threads service each connection n turn.
__________________ Until you can build a working general purpose reprogrammable computer out of basic components from radio shack, you are not fit to call yourself a programmer in my presence. This is cwhizard, signing off. |
| abachler is offline | |
| | #5 | ||
| Registered User Join Date: May 2008 Location: Australia
Posts: 198
| Quote:
Maybe a parallel vector of threads and sockets (ints)?
__________________ Quote:
Last edited by pobri19; 03-22-2009 at 03:32 AM. | ||
| pobri19 is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| telnet server, how to program a backspace | Mastermosley | C# Programming | 5 | 03-22-2009 02:14 AM |
| Advice on writing a basic encryption program? | osiris^ | C Programming | 2 | 09-10-2007 02:02 PM |
| Using variables in system() | Afro | C Programming | 8 | 07-03-2007 12:27 PM |
| Function in a Server program | nick048 | C Programming | 1 | 03-31-2007 01:41 AM |
| First Program need advice | A10 | C++ Programming | 14 | 11-29-2006 11:00 PM |