Solved

ActiveX TTCP disconnection Problems

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

Enroll in June's Course of the Month

June’s Course of the Month is now available! Experts Exchange’s Premium Members, Team Accounts, and Qualified Experts have access to a complimentary course each month as part of their membership—an extra way to sharpen your skills and increase training.

Question has a verified solution.

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

Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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