Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Re: Need advice - Synapse - Connection Reset by Peer
| Subject: | Re: Need advice - Synapse - Connection Reset by Peer |
| Posted by: | "Mat Ballard" (m..@chemwares.com) |
| Date: | Wed, 2 Aug 2006 10:15:58 |
g'day theo,
thanks for your reply - have downloaded your demo and will study it *very
carefully*.
As for the strange design, this is due to the following.
The Win32 GUI app performs very complex and memory-intensive manipulations of
images; crudely speaking, it does:
NewImage := function(Image1, Image2, Image3, Very_Long_List_of_Parameters).
We have a customer who loves what this Win32 GUI app can do, and then asked:
"but how can we make it talk to our Unix C++ processes ? By September."
After thinking about it, the best way forward seemed to be to "bolt on" TCPIP
server capability, and also client capability for testing purposes. The GUI app
can then be run as a server, or as a client, but not both at the same time. The
GUI_Client then throws {Image1, Image2, Image3, Very_Long_List_of_Parameters} to
the GUI_Server, which calculates NewImage and throws it back to GUI_Client.
There will not be more than one connection at a time, and trying to do two sets
of calculation at the same time is a Very_Bad_Idea because the calculations are
very CPU and Memory intensive (~100 - 1000 MB, 10 - 500 s).
The problem is that the client is disconnecting before it sends it data;
GUI_Client does:
Sock.Connect(ServerEdit.Text, PortNEdit.Text);
i := Sock.LastError;
if (i = 0) then
begin
Sock.SendString('Hello Server !'); <- this is sent without error
...
Misc.Wait(10000, FALSE); <- wait 10 s before closing socket
Sock.CloseSocket;
this then hits the listening thread on the GUI_Server:
FSock.Listen;
repeat
if Self.Terminated then break;
if FSock.CanRead(PollEvery) then
begin
FClientSock := 0;
FClientSock := FSock.Accept;
if (FSock.LastError = 0) and Assigned(SynchMethod) then
Synchronize(SynchMethod); <- jump back to main GUI thread here
which then hits SynchMethod in the main GUI:
Sock := TTCPBlockSocket.Create;
try
Sock.Socket := ServerDaemon.ClientSock; // 1668
Sock.GetSins;
repeat
Str := Sock.RecvString(1000); <- this fails
if (Sock.LastError = 0) then <- error 10054 here
9000 ms later, the GUI_Client does Sock.CloseSocket;
So the GUI_Client hasn't actually closed its socket until after the GUI_Server
has whinged about 10054 (Connection Reset by Peer).
So I am somehow losing the connection, but cannot see where.
cheers,
Mat