Board index » delphi » Blocking of messages

Blocking of messages

J'm writting an client-server application in Borland Delphi 5.0 and J'm
using components ClientSocket and ServerSocket for communication beetween
clients and server. Programs seemed to work smoothly, but suddenly I noticed
something strange in server app.:

-when appeared one after another two events OnClientRead during I was
resizing or moving the server window, the program hunged up and stopped
reacting for the user interface !

Maybe will help ProcessMessages() , but I don't know where to insert the
call. Probably not into every event in Object Inspector ? Maybe it is due to
redefine  message loop ?

George

 

Re:Blocking of messages


Quote
In article <3b3e4000_1@dnews>, George wrote:
> J'm writting an client-server application in Borland Delphi 5.0 and J'm
> using components ClientSocket and ServerSocket for communication beetween
> clients and server. Programs seemed to work smoothly, but suddenly I noticed
> something strange in server app.:
> -when appeared one after another two events OnClientRead during I was
> resizing or moving the server window, the program hunged up and stopped
> reacting for the user interface !

You should never use nonblocking sockets in a server application in my
opinion. This forces all processing of incoming socket data to the main thread
and will be a serious bottleneck if you ever have more than one client
connecting to the server at the same time. And as you noticed the socket data
events depend on processing messages. If you do something on the server that
blocks message processing in the main thread for some time you freeze the
clients as well. Sprinkling the code with ProcessMessages call will only make
the mess deeper. A server app using sockets needs to have a proper
multithreaded design, using blocking sockets and a separate thread for each
incoming connection. You use the serversockets OnGetThread event to create a
worker thread for a connection.

If you are new to threads i recomment this intro:

http://www.pergolesi.demon.co.uk/prog/threads/ToC.html

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Re:Blocking of messages


Uzytkownik "Peter Below (TeamB)" <100113.1...@compuXXserve.com> napisal w
wiadomosci

Quote
> You should never use nonblocking sockets in a server application in my
> opinion. This forces all processing of incoming socket data to the main
thread
> and will be a serious bottleneck if you ever have more than one client
> connecting to the server at the same time. And as you noticed the socket
data
> events depend on processing messages. If you do something on the server

that

Does it mean that every socket thread will have own events queue ?
And what will happen if I set blocking ClientSocket ?

Re:Blocking of messages


Quote
In article <3b3f565e$1_1@dnews>, George wrote:
> Does it mean that every socket thread will have own events queue ?

What do you mean by "event queue"? In a Win32 app only the main thread
has a message queue by default. Other threads can have a message queue
but it has to be created and the thread then needs a message loop. This
is rarely needed. In a multithreading app using blocking sockets you
don't process any events in the client threads, you create a
TWinSocketStream inside the thread and then simply try to read from it
or write to it. The request will block until data is available on a
read (or until the timeout you selected expires).

Peter Below (TeamB)  100113.1...@compuserve.com)
No e-mail responses, please, unless explicitly requested!
Note: I'm unable to visit the newsgroups every day at the moment,
so be patient if you don't get a reply immediately.

Other Threads