?
Solved

ActiveX TTCP disconnection Problems

Posted on 1998-01-21
2
Medium Priority
?
166 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 200 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

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…
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.
Suggested Courses
Course of the Month11 days, 5 hours left to enroll

770 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