Solved

Error reading from socket (DataSnap)

Posted on 2003-12-11
10
1,513 Views
Last Modified: 2007-12-19
Hi,
 
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.
 
Enviroment:
  Delphi 7
 
  DATABASESERVER
  * Interbase 7.1
 
  APPLICATIONSERVER
  * dbExpress components
 
  CLIENT
  * TSocketConnection
  * TClientDataSet
0
Comment
Question by:olmy
  • 4
  • 4
  • 2
10 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9919326
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.
0
 
LVL 7

Expert Comment

by:Motaz
ID: 9919402
Did you tried other threading model than you are using?

Apartment/Neutral/Both, etc

and are you using TMultiReadExeclusiveWriteSyncronizer to protect your critical sections?

Motaz
0
 
LVL 1

Author Comment

by:olmy
ID: 9926233
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.

Thanks
  Janne
0
 
LVL 8

Assisted Solution

by:gmayo
gmayo earned 125 total points
ID: 9926739
"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.
0
 
LVL 1

Author Comment

by:olmy
ID: 9926865
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.
  Janne
0
Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

 
LVL 8

Expert Comment

by:gmayo
ID: 9926946
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.
0
 
LVL 1

Author Comment

by:olmy
ID: 9940748
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?

Regards
    Janne Timmerbacka
0
 
LVL 7

Accepted Solution

by:
Motaz earned 125 total points
ID: 9940973
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

Motaz
0
 
LVL 1

Author Comment

by:olmy
ID: 9947968
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.
***********************************************
type
  TExceptedSocketConnection = class(TSocketConnection)
  protected
    procedure DoError(E: Exception); override;
  end;

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

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

procedure TForm1.Button12Click(Sender: TObject);

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

    except
      (* 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;
  begin
    iCounter := 1;
    result := false;

    while not _DoCall do
    begin
      application.processmessages;

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

    result := true;
  end;

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

Regards
  Janne Timmerbacka
0
 
LVL 8

Expert Comment

by:gmayo
ID: 9948075
Fine with me, thanks.

Geoff M.
0

Featured Post

How to improve team productivity

Quip adds documents, spreadsheets, and tasklists to your Slack experience
- Elevate ideas to Quip docs
- Share Quip docs in Slack
- Get notified of changes to your docs
- Available on iOS/Android/Desktop/Web
- Online/Offline

Join & Write a Comment

Suggested Solutions

In this tutorial I will show you how to use the Windows Speech API in Delphi. I will only cover basic functions such as text to speech and controlling the speed of the speech. SAPI Installation First you need to install the SAPI type library, th…
Hello everybody This Article will show you how to validate number with TEdit control, What's the TEdit control? TEdit is a standard Windows edit control on a form, it allows to user to write, read and copy/paste single line of text. Usua…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now