| View previous topic :: View next topic |
| Author |
Message |
Cheat Engine User Something epic
Reputation: 61
Joined: 22 Jun 2007 Posts: 2071
|
Posted: Tue Dec 29, 2009 7:55 pm Post subject: So, I've got a bit of an issue with my socket server. |
|
|
It's going berserk on the CPU (load is around the 90 all the time). It's a multiclient one and it works fine but this CPU load worries me, is it a common problem/normal and what is causing it?
I am running on a Windows Server (2003 I believe) and I am using winsock (2.2)
|
|
| Back to top |
|
 |
Slugsnack Grandmaster Cheater Supreme
Reputation: 71
Joined: 24 Jan 2007 Posts: 1857
|
Posted: Tue Dec 29, 2009 8:15 pm Post subject: |
|
|
| Nope, it's not. Got any code to show us ?
|
|
| Back to top |
|
 |
Cheat Engine User Something epic
Reputation: 61
Joined: 22 Jun 2007 Posts: 2071
|
Posted: Tue Dec 29, 2009 8:22 pm Post subject: |
|
|
| Slugsnack wrote: | | Nope, it's not. Got any code to show us ? | Yes I do have the code to show it. But I have nothing to tell besides that I am looping in a while (in main()) and in that I first accept all clients, check for receiving stuff.
| Code: | while(LOOP)
{
t.check();
accept_connections();
receive_data();
} |
It's all that is currently interesting. t.check is a timer that checks if some time has passed and sends something to all clients if it did.
the rest is pretty obvious.
|
|
| Back to top |
|
 |
Dark Byte Site Admin
Reputation: 475
Joined: 09 May 2003 Posts: 25985 Location: The netherlands
|
Posted: Tue Dec 29, 2009 9:06 pm Post subject: |
|
|
I think "select" might be of some use here
_________________
Tools give you results. Knowledge gives you control.
Like my help? Join me on Patreon so i can keep helping |
|
| Back to top |
|
 |
Cheat Engine User Something epic
Reputation: 61
Joined: 22 Jun 2007 Posts: 2071
|
Posted: Tue Dec 29, 2009 11:00 pm Post subject: |
|
|
| Dark Byte wrote: | | I think "select" might be of some use here | Explain what you mean.
|
|
| Back to top |
|
 |
tombana Master Cheater
Reputation: 2
Joined: 14 Jun 2007 Posts: 456 Location: The Netherlands
|
Posted: Wed Dec 30, 2009 6:10 am Post subject: |
|
|
| Holland wrote: | | Dark Byte wrote: | | I think "select" might be of some use here | Explain what you mean. |
He means that normal winsock functions will block. That means that if you call recv() on a socket, it will hold your program until some data arrives. If you have multiple client then this will be a problem. So you can use the function 'select' to first check which clients have send data and then only call recv() on those specific sockets.
There are some other methods as well, they are listed here with their pros and cons:
http://tangentsoft.net/wskfaq/articles/io-strategies.html
It also depends on how many clients you will handle.
If you already have a window in your program I would strongly advise you to use asynchronous sockets because they are very easy to implement.
|
|
| Back to top |
|
 |
|