Newsgroups : Borland : borland.public.delphi.internet.winsock : 2006 Aug : Need advice - Synapse - Connection Reset by Peer

www.cryer.info
Managed Newsgroup Archive

Need advice - Synapse - Connection Reset by Peer

Subject:Need advice - Synapse - Connection Reset by Peer
Posted by:"Mat Ballard" (m..@chemwares.com)
Date:Tue, 1 Aug 2006 12:41:54

Hi everyone,

I'm new to the world of winsock apps and am getting the dreaded error 10054 -
Connection Reset by Peer.

I'm using the Synapse TTCPBlockSocket component.

At the moment I'm just trying to send a text message from client to server, and
have the server display the message in the main thread VCL GUI.

Since the ultimate aim is to perform memory-intensive graphical manipulations in
response to a client request, I have designed the server application to have a
listening thread that then Synchronizes back to the main VCL thread to perform
the actual communication. I know that most designs (eg: "Echo") will instead
spawn a worker thread, but I want to serialize "sessions" to maximize available
memory, and also because of the graphical manipulations, which I understand can
only be performed in the main VCL thread anyway.

My client code is:


procedure TClientForm.ConnectActionExecute(Sender: TObject);
var
  Sock: TTCPBlockSocket;
begin
  Sock := blcksock.TTCPBlockSocket.Create;
  Sock.CreateSocket; // does nothing ?
  Sock.SetLinger(true, 10);
  Sock.Connect(ServerEdit.Text, PortNEdit.Text);
  if (Sock.LastError = 0) then
  begin
    Sock.SendString('Hello Server !');
    SendMemo.Lines.Add('Hello Server !');
  end else begin
    ShowMessageFmt('Internet Communication Error' + #13#10#13#10 + '%s',
[Sock.LastErrorDesc]);
  end;
  Sock.CloseSocket;
  Sock.Free;
end;


and my relevant server code is:


  ServerDaemon := TTCPServerDaemon.Create;
  ServerDaemon.SynchMethod := SynchMethod;
  ServerDaemon.Port := PortNEdit.Text;
  ...

procedure TTCPServerDaemon.Execute;
begin
  FSock.CreateSocket;
  FSock.SetLinger(true, 10);
  FSock.Bind('0.0.0.0', Self.Port);
  FSock.Listen;
  repeat
    if Self.Terminated then break;
    if FSock.CanRead(1000) then
    begin
      FClientSock := 0;
      FClientSock := FSock.Accept;
      if (FSock.LastError = 0) and Assigned(SynchMethod) then
        Synchronize(SynchMethod);
// = jump back to main VCL thread to grab data and perform calculations
    end;
  until false;
end;

  ...

procedure TServerForm.SynchMethod;
var
  Sock : TTCPBlockSocket;
  Str: String;
begin
  ReceiveMemo.Lines.Add('We got hit !');
  Sock := TTCPBlockSocket.Create;
  KillConnectionBitBtn.Tag := 0;
  KillConnectionBitBtn.Enabled := TRUE;

  try
    Sock.Socket := ServerDaemon.ClientSock; // yes, it gets a valid socket, 1668
    Sock.GetSins;
{FSock.LocalSin =  (2, 2, 49425, (('', #0, #0, #1), (127, 256), 16777343), (#0,
#0, #0, #0, #0, #0, #0, #0), 49425, 16777343, ((#0, #0, #0, #0, #0, #0, #0, #0,
#0, #0, #0, #0, #0, #0, #0, #0), (0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0)), 0)
FSock.RemoteSin = (2, 2, 6929, (('', #0, #0, #1), (127, 256), 16777343), (#0,
#0, #0, #0, #0, #0, #0, #0), 6929, 16777343, ((#0, #0, #0, #0, #0, #0, #0, #0,
#0, #0, #0, #0, #0, #0, #0, #0), (0, 0, 0, 0, 0, 0, 0, 0), (0, 0, 0, 0)), 0)}
    repeat
      Application.ProcessMessages;
      if (KillConnectionBitBtn.Tag > 0) then
        break;
      Str := Sock.RecvString(ReadTimeoutNEdit.AsInteger);
      ReceiveMemo.Lines.Add(Str);
      if (Sock.LastError <> 0) then
      begin
        ShowMessageFmt('Internet Communication Error' + #13#10#13#10 + '%s',
[Sock.LastErrorDesc]);
        break;
      end;
    until false;
  finally
    Sock.Free;
    KillConnectionBitBtn.Enabled := FALSE;
    KillConnectionBitBtn.Tag := 0;
  end;
end;


Any hints on how to progress this problem would be greatly appreciated,


Thanks in advance,


Mat

Replies:

www.cryer.info
Managed Newsgroup Archive