Sriram A Nandakumar
2003-08-01 11:37:31 UTC
Hi,
I have a requirement based on sockets and seem to be quite lost with the
options that I have on hand. Before I proceed here is my functional
requirement - I have a COM dll which will be contacting my server
application - not a service - but a plain application with a Server socket
in it (there could be multiple requests from clients at the same time). The
server receives this data and then does some processing - which might take
upto a minute max and then give back the result. Due to few reasons we plan
to stick to TServerSocket and TClientSocket itself.
What combination of sockets is best:
a) A Non blocking server and a Blocking client - On receiving text I create
a thread and pass the socket object to the thread and then start my
process.So if I receive 10 requests simultaneously, I create 10 threads.
However, there will be a Accept 'x' requests option. The sample test
application works okay. However, there was no way I could create a scenario
for data loss. On the client side I use a TWinSocketStream to send and read
data.
The issue found is if the server closes the connection then it works fine -
if the client closes the connection then it starts throwing up errors. Am I
missing anything here?
Also, if there is the network goes down, then TCustomWinSocket's (i really
wonder why this was done), WndProc method call Application.HandleException.
Since I create a thread for each request I could land up in a big mess with
all the windows opening up - otherwise too I donot want a error message
thrown and shown by the App.To resolve I inherited from TCustomWinSocket and
implemented the message handler - CM_SOCKETMESSAGE.
procedure CMSocketMessage(var Message: TCMSocketMessage); message
CM_SOCKETMESSAGE;
What i do is basically protect the method with try .. except and call
inherited. IS THIS OK?
This is what is created in the OnGetSocket event.
Note: I donot want to handle these in the Application.OnException :).
b) A Thread Blocking Server and a Blocking client - In the OnGetThread event
create a thread and allow the thread to take care from there. However, found
that at any one point of time only one connection can be active on a
particular port. The other requests gives a nasty 'Read Error 64'. I could
be wrong here though. In this case used TWinSocketStream both places. The
only problem in this case was the Read Error 64. I am quite confused with
what the help says 'the execution of the connection thread is suspended
while reading or writing until all information has been transferred over the
connection'. Does this mean a Thread blocking server will stop listening
until the connection on hand is complete?
In this method got stuck with Read error and so did not bother to try the
other issues that were found in type a).
Are there any other options available or should I go about doing the above
in the right way? Would be excellent if a sample application is made
available.
Help, suggestions highly appreciated.
Thanx in advance
Sri Ram
I have a requirement based on sockets and seem to be quite lost with the
options that I have on hand. Before I proceed here is my functional
requirement - I have a COM dll which will be contacting my server
application - not a service - but a plain application with a Server socket
in it (there could be multiple requests from clients at the same time). The
server receives this data and then does some processing - which might take
upto a minute max and then give back the result. Due to few reasons we plan
to stick to TServerSocket and TClientSocket itself.
What combination of sockets is best:
a) A Non blocking server and a Blocking client - On receiving text I create
a thread and pass the socket object to the thread and then start my
process.So if I receive 10 requests simultaneously, I create 10 threads.
However, there will be a Accept 'x' requests option. The sample test
application works okay. However, there was no way I could create a scenario
for data loss. On the client side I use a TWinSocketStream to send and read
data.
The issue found is if the server closes the connection then it works fine -
if the client closes the connection then it starts throwing up errors. Am I
missing anything here?
Also, if there is the network goes down, then TCustomWinSocket's (i really
wonder why this was done), WndProc method call Application.HandleException.
Since I create a thread for each request I could land up in a big mess with
all the windows opening up - otherwise too I donot want a error message
thrown and shown by the App.To resolve I inherited from TCustomWinSocket and
implemented the message handler - CM_SOCKETMESSAGE.
procedure CMSocketMessage(var Message: TCMSocketMessage); message
CM_SOCKETMESSAGE;
What i do is basically protect the method with try .. except and call
inherited. IS THIS OK?
This is what is created in the OnGetSocket event.
Note: I donot want to handle these in the Application.OnException :).
b) A Thread Blocking Server and a Blocking client - In the OnGetThread event
create a thread and allow the thread to take care from there. However, found
that at any one point of time only one connection can be active on a
particular port. The other requests gives a nasty 'Read Error 64'. I could
be wrong here though. In this case used TWinSocketStream both places. The
only problem in this case was the Read Error 64. I am quite confused with
what the help says 'the execution of the connection thread is suspended
while reading or writing until all information has been transferred over the
connection'. Does this mean a Thread blocking server will stop listening
until the connection on hand is complete?
In this method got stuck with Read error and so did not bother to try the
other issues that were found in type a).
Are there any other options available or should I go about doing the above
in the right way? Would be excellent if a sample application is made
available.
Help, suggestions highly appreciated.
Thanx in advance
Sri Ram