Solved

ActiveX TTCP disconnection Problems

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

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

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…
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

747 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

10 Experts available now in Live!

Get 1:1 Help Now