Solved

ActiveX TTCP disconnection Problems

Posted on 1998-01-21
2
158 Views
Last Modified: 2010-04-04
I wrote two small programs with the ActiveX-Controll TTCP of the INTERNET-Components. One is a small TCPIP-Server and the other is a small TCPIP-Client. I can connect with the client to the server, sending data and so on. But when I close the connection with the client, the server closes correct the connecting and the client is also closing the connection. But with NETSTAT.EXE I can see, that the connection at the client is already on the state "TIME-WAIT". After several minutes the connection closes.

Here my question: "What could I do, that the connecting is closing correctly and dont hang 3-5 minutes?"
0
Comment
Question by:CCUde
2 Comments
 
LVL 5

Expert Comment

by:ronit051397
ID: 1357207
NetManage said that on the OnClose event of the TCP you have to call Close(Close the TCP). Bizzar, but that's what they said.
0
 

Accepted Solution

by:
mshaw earned 100 total points
ID: 1357208
I assume the problem you have is with the client program, so all event handlers mentioned here are to do with the client.

First of all, do not create the TCP component at design time, do it at run time, perhaps in the form create method of the client's main form.

When the server closes the connection on the client, the client's TCP's OnClose event handler is activated. As ronit suggested, in here you do call the TCP's Close method.

NetStat will indicate that the connection is on TIME_WAIT, preventing you connecting to the same remote connection point. ie if you try and re-connect, it wont be able to re-connect until NetStat indicates that the connection is properly closed.

To get around this, every time you disconnect (either the client disconnecting from the server deliberately, or the client being disconnected from the server involuntarily), you should destroy the TCP component, and create it again.
Although this doesnt close the connection between the local port and the remote port properly, it does allow the client to re-connect to the server again.

I assume the server program would be based on the same principle, but I use a server program running on a unix box.

To summarize, here's a snippet of code - which hasnt been tested, but is the essential code from my working client app.
type TClientMainform = class(TForm)
  aTCP : TTCP;
...


procedure TClientMainform.FormCreate(Sender:TObject);
begin
  ReCreateTCPComponent
end;

procedure TClientMainform.ReCreateTCPComponent;
//create component and set up event handlers
begin
  aTCP.Free;
  aTCP := nil;
  aTCP := TTCP.Create(self);
  aTCP.OnClose := TClientMainform.OnTCPClose;
  aTCP.OnConnect := TClientMainform.OnTCPConnect;
  aTCP.OnError := ...
  aTCP.OnDataArrival := ....
end;

procedure TClientMainform.OnTCPClose(Sender:TObject);
begin
  ReCreateTCPComponent;
end;

Email me if this isnt what you're asking, or have any problems with it. mshaw@cccgroup.co.uk
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Reconfigure Delphi Install? 2 46
LAN or WAN ? 11 81
Base1 Encode/Decode 3 67
DBGrid or StringGrid ? 6 68
Introduction The parallel port is a very commonly known port, it was widely used to connect a printer to the PC, if you look at the back of your computer, for those who don't have newer computers, there will be a port with 25 pins and a small print…
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…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

911 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

21 Experts available now in Live!

Get 1:1 Help Now