Solved

ActiveX TTCP disconnection Problems

Posted on 1998-01-21
2
159 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

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

This article explains how to create forms/units independent of other forms/units object names in a delphi project. Have you ever created a form for user input in a Delphi project and then had the need to have that same form in a other Delphi proj…
In my programming career I have only very rarely run into situations where operator overloading would be of any use in my work.  Normally those situations involved math with either overly large numbers (hundreds of thousands of digits or accuracy re…
This Micro Tutorial hows how you can integrate  Mac OSX to a Windows Active Directory Domain. Apple has made it easy to allow users to bind their macs to a windows domain with relative ease. The following video show how to bind OSX Mavericks to …
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…

803 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