Error reading from socket (DataSnap)

I have a strange problem. Downloading smaller amounts of data from the server works always, but sometimes when client downloads larger amount of data, "Error
reading from socket" error is raised on client. This happens when "refresh" is called for TClientDataSet.
Any ideas what could cause this! It happens many times per day.
  Delphi 7
  * Interbase 7.1
  * dbExpress components
  * TSocketConnection
  * TClientDataSet
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Without knowing anything about TClientDataSet, it could be a buffer overflow. Are there any settings anywhere you can change to increase the socket buffer size?

Geoff M.
Did you tried other threading model than you are using?

Apartment/Neutral/Both, etc

and are you using TMultiReadExeclusiveWriteSyncronizer to protect your critical sections?

olmyAuthor Commented:
Hi, as far as I know, there are no buffer settings to adjust.

I'm using (ciMultiInstance, tmApartment). I haven't tried other models. Error dosen't come that often, so it's hard to really be sure what change makes the difference. I have used TCriticalSection to protect the critical sections.

The problem appears, even there is only one client connected to the server. Could that rule critical sections and threading model out? Also, there can be two users and one of them has no troubles, but the other one having the trouble at the same time. The server dosen't seem to be locked or blocked in anyway, the transmission starts and suddenly stops.

Do you have more information what "Error reading from socket" error means? I don't fully understand the situation and I'm not sure what to check next.

Introduction to R

R is considered the predominant language for data scientist and statisticians. Learn how to use R for your own data science projects.

"Error reading from socket" usually means the socket was open but has unexpectedly closed while attempting to read from it. At least that's the socket type of message. However, it could be your TClientDataSet raising that error which could mean that it has lost some data somewhere. It's a tough one without being able to debug exactly what is going on.

Geoff M.
olmyAuthor Commented:
Could internet connection problems create these problems. Sometimes when I download files via internet to these client computers, the downloaded files have become corrupted! After redownload they work fine. Some of these clients are connected via internet + VPN.
Yes, Internet problems could cause this, although I obviously cannot say whether that is really your problem. I've got some software that can be played over the Internet and that loses data if I send it too fast (using TClientSocket and TServerSocket).

Geoff M.
olmyAuthor Commented:
I have a feeling that the problems might be caused by problems in a fysical network. Is so, does anybody have ideas how to make Datasnap communication more fault tolerant? Maybe a automatic retry when communication fails for one reason or another?
I noticed that the "error reading from socket" error worked differently in try...except-block. Debugger also informed that the error was something "first chance exception...". Does anybody know more about that?

    Janne Timmerbacka
when I get this error I close the connection, If I do not close the connection, then I should close the application and open it again to resume communication with server


Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
olmyAuthor Commented:
Thank you. The problem is now solved. I don't know what the network problem was, but I managed to make the communications more fault tolerant. I would like to split point with Gmayo and Motaz 50%/50% - is it ok for you?
  * Gmayo game me tip of what could cause the problem
  * Motaz gave me important tip for disconnecting, because that breaks the dispatcher loop

Example code below shows how the error situation was handled.
  TExceptedSocketConnection = class(TSocketConnection)
    procedure DoError(E: Exception); override;

procedure TExceptedSocketConnection.DoError(E: Exception);
  (* close the connection to break the dispatcher loop *)

  inherited DoError( E );
end;(* DoError *)

procedure TForm1.Button12Click(Sender: TObject);

  function _DoCall: Boolean;
    Result := false;
      (* reconnect if connection does not exist *)
      if not ClientDataSet1.RemoteServer.Connected then
      Result := true;

      (* next: save error to file, instead of showing it *)
      on E: Exception do ShowMessage( E.Message );
    end;(* try *)
  end;(* _DoCall *)

  function _Try : boolean;
  var icounter : byte;
    iCounter := 1;
    result := false;

    while not _DoCall do

      inc( iCounter );
      (* do not try forever *)
      if iCounter > 5 then exit;
    end;(* while *)

    result := true;

  SocketConnection := TExceptedSocketConnection.create( self );
  ClientDataSet1.RemoteServer := SocketConnection;
    FreeAndNil( SocketConnection );
  end;(* try *)

  Janne Timmerbacka
Fine with me, thanks.

Geoff M.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today

From novice to tech pro — start learning today.