byungho
asked on
TCP Client(Indy10) with VPN can not detect disconnect when VPN disconnected!!
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.Tex t;
Synchronize(DoReadyToWait) ;
while not Terminated and not Application.Terminated do
begin
if WAIT_OBJECT_0 = WaitForSingleObject(FAbort Event.Hand le, 10) then
Exit // Aborted
else
begin
TCP.GetResponse(300); // read wait until received msg infinitly!!!
FData := TCP.LastCmdResult.Text.Tex t;
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;
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
TCP.GetResponse(200); // read wait ok response
S1 := TCP.LastCmdResult.Text.Tex
Synchronize(DoReadyToWait)
while not Terminated and not Application.Terminated do
begin
if WAIT_OBJECT_0 = WaitForSingleObject(FAbort
Exit // Aborted
else
begin
TCP.GetResponse(300); // read wait until received msg infinitly!!!
FData := TCP.LastCmdResult.Text.Tex
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;
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I wrote ping/pong from server to client! But it's not work correctly.. -_-;
Now, I work ping/pong from client to server!!
Now, I work ping/pong from client to server!!
Forced accept.
Computer101
EE Admin
Computer101
EE Admin
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).