Solved

why  the cpu usage goes to 100% when the the idtcpclient connects to idtcpserver

Posted on 2007-11-18
4
879 Views
Last Modified: 2012-05-05
I did a simple program that connects a component tidtcpclient to tidtcpserver, but when it connects the server, on the server side the cpu usage goes to 100%, and stay on it, so why this happaning? and this is normal? i only connected, that's it.
0
Comment
Question by:rafaelrgl
  • 2
4 Comments
 
LVL 28

Accepted Solution

by:
2266180 earned 300 total points
ID: 20309173
I think I know what the problem is. you are not using the servers onexecute event, or are using it incorrectly.

all processing must be done in the server onexecute event using the parameter which identifies the thread (from which you get the connection object). that event is beeing executed in the context of that specific thread, so keep in mind that you will have to synchronize access to any shared resources.

if you don't want to use that event (I've had such an application myself where I just notified another thread of the existing data and the server processed it whenever it got time), you simply assign the event and in it you doo a sleep(5); (very small value).
this will make sure that :
- your server's client thread doesn't get blocked for too much time
- AND, the cpu is not used extensivly.

because what happens is that as long as there is some data to be read from the client end, the server will keep executing that event. so if you don't process data in it, it will be executed in a loop very fast ;)
0
 
LVL 17

Assisted Solution

by:TheRealLoki
TheRealLoki earned 100 total points
ID: 20309375
can you show us your server's code please.
I think Ciuly is right, you are probably using the OnConnect event instead of the OnExecute event.
0
 
LVL 19

Assisted Solution

by:MerijnB
MerijnB earned 100 total points
ID: 20311270
alternatively, if you are not familiar with sync programming, use something like ICS (free): http://www.overbyte.be/frame_index.html?redirTo=/products/ics.html
0
 
LVL 28

Expert Comment

by:2266180
ID: 20311348
(this is an addition/extension to merijnb's post)

it's not really sycn programming. indy uses blocking (synchronous) sockets whereas ics uses non-blocking (asyncronous) sockets. so it's not the programming style but the socket type. and in both cases, the basic style is to use events, the difference is the way those events are fired and processed. and of course that the socket type induces a certain programming style, but I for example have made 2 systems until today that can use blocking sockets in a non-blocking fashion. of course, the unrelying atomic data is a (n xml) command so the event is fired when such a command is available to be processed.
what I want to say is that no matter of the socket type you can use any programming style, but you'll just have to be carefull :)

basically, both types of sockets are best fit for specific types of applications (complementary). and as I said above, both types of sockets can be used in the other types of applications where they don't fit so well.
0

Featured Post

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Although Jacob Bernoulli (1654-1705) has been credited as the creator of "Binomial Distribution Table", Gottfried Leibniz (1646-1716) did his dissertation on the subject in 1666; Leibniz you may recall is the co-inventor of "Calculus" and beat Isaac…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

830 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question