Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

TCP Client(Indy10) with VPN can not detect disconnect when VPN disconnected!!

Posted on 2006-11-27
5
Medium Priority
?
689 Views
Last Modified: 2010-04-04
I'm use Indy10.

I can not sure TIdTCPClient is buggy or VPN Client is buggy!! The situation is:

My client work in VPN to communicate server!!

My client connect to tcp server(TIdTCPServer)  and read until server sent infinitly!!

When VPN was disconnected, TCP.GetResponse() does not throw exception like EIdDisconnected or EIdConClosedGracefully!!

Is it possible like that?

Someone tell me DON'T read wait infinitly, USE ping/pong client with server periodically!!

Is it good solution to establish valid connection ?

What about set read timeout for TIdTCPClient when TIdTCPClientGetResponse()?


Here is code:

procedure TWaitThread.Execute;
var
  TCP: TIdTCPClient;
  S1, S2: string;
begin
  inherited;

  FAbortEvent.ResetEvent;

  TCP := nil;
  try try
    while not Terminated do
    begin
      if nil = TCP then
      begin
        TCP := TIdTCPClient.Create(nil);
        TCP.ReadTimeout := 0;
        TCP.Host := FHost;
        TCP.Port := FPort;
      end;

      if not Tcp.Connected then
      try
        TCP.Connect;
      except
        FreeAndNil(TCP);
      end;
       
      if (nil <> TCP) and (TCP.Connected) then
      try
        S1 := TCP.Socket.ReadLn; // read welcome response
        TCP.Socket.WriteLn('client ' + FClientData);
        TCP.GetResponse(200); // read wait ok response
        S1 := TCP.LastCmdResult.Text.Text;

        Synchronize(DoReadyToWait);

        while not Terminated and not Application.Terminated do
        begin
          if WAIT_OBJECT_0 = WaitForSingleObject(FAbortEvent.Handle, 10) then
            Exit // Aborted
          else
          begin
            TCP.GetResponse(300); // read wait until received msg infinitly!!!  

            FData := TCP.LastCmdResult.Text.Text;
            Synchronize(DoNotify);
          end;
        end;
      except
        if nil <> TCP then
          FreeAndNil(TCP);
      end;

      Sleep(3000); // wait 3 sec, if disconnected
    end;

  except
  end;
  finally
    if nil <> TCP then
    begin
      if TCP.Connected then TCP.Disconnect;
      FreeAndNil(TCP);
    end;
  end;
end;
0
Comment
Question by:byungho
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
5 Comments
 
LVL 19

Accepted Solution

by:
MerijnB earned 500 total points
ID: 18025885
using ping/pong (or keepalives) is always a good idea. This is the only way to make sure the connection is there or not when you don't have to sent actually. It is possible you 'think' you can send data, but it never arrives at the other end.
0
 
LVL 19

Expert Comment

by:MerijnB
ID: 18025892
What about set read timeout for TIdTCPClient when TIdTCPClientGetResponse()?

oops, forgot about this one: this could work, but only if you are sure you _should_ receive data from the other side. So if you sometimes have a pause in the dataflow, look for a solution using keepalives (see above).
0
 

Author Comment

by:byungho
ID: 18034197
I wrote ping/pong from server to client! But it's not work correctly.. -_-;

Now, I work ping/pong from client to server!!
0
 
LVL 1

Expert Comment

by:Computer101
ID: 21135795
Forced accept.

Computer101
EE Admin
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Objective: - This article will help user in how to convert their numeric value become words. How to use 1. You can copy this code in your Unit as function 2. than you can perform your function by type this code The Code   (CODE) The Im…
Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
In response to a need for security and privacy, and to continue fostering an environment members can turn to for support, solutions, and education, Experts Exchange has created anonymous question capabilities. This new feature is available to our Pr…
Suggested Courses

618 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