Solved

TCP/IP waitting time

Posted on 2002-06-12
5
380 Views
Last Modified: 2010-04-04
I am using Indy IdTCPServer and IdTCPClient to build two programs that run on different computers.
Normally, IdTCPClient sends a text to IdTCPServer without problem. Sometimes if the computer that has IdTCPServer is not swithed on then IdTCPClient got error. That is acceptable, but the problem is the program is frozen to waiting the error, it normally waits for more than 15 seconds. I wish the program can only wait for 2 or 3 seconds, that means if it cannot find the destination computer(by computer name or IP address) in 2 or 3 seconds then returns an error immediately. How can I do this?
BTW, I do have to use Indy.

Thank u very much in advance.


Peter
0
Comment
Question by:petershaw9
  • 3
5 Comments
 
LVL 1

Expert Comment

by:_MeSSiah_
ID: 7072578
You can use the ReadTimeout property of TidTCPClient and set it to number of miliseconds.

If you get the error on connecting, try to connect like this:

idTCPClient1.Connect(3000);

The 3000 is a timeout in miliseconds. In my case, the client will wait exactly 3 seconds for the server to accept the connection.

Also a small off topic tip: Drop a TidAntiFreeze component on your client's main form, so the application won't freeze during transmissions and socket operations.
0
 
LVL 1

Expert Comment

by:_MeSSiah_
ID: 7072582
Oh, i forgot...like Connect method, other functions (like ReadLn for ex.) have an ATimeOut parameter, that is set to -1 by default. You can override it mannualy on each call or use ReadTimeout property.

(i'm talking about Indy 9.x and higher)
0
 
LVL 14

Expert Comment

by:DragonSlayer
ID: 7074445
or you can do all these operations in a separate thread of its own.
0
 

Author Comment

by:petershaw9
ID: 7077815
Hi,
Firstly, thank u for your help.
I am using Delphi 6. The Indy's TCPClient has not ReadTimeOut property. and the connect method does not have parameters required. I am first time do TCP/IP programming. I firstly use TCPClient.connect method to connect to TCPSever. and then use TCPClient.WriteLn to send msg. The problem occurred at Connect method. So do I have to connect first? I guess, Yes.

If Delphi 6 does not use Indy 9.x, is any other way to solve the problem or I can download Indy 9.x?


peter
0
 
LVL 1

Accepted Solution

by:
_MeSSiah_ earned 200 total points
ID: 7077918
Delphi 6 comes with Indy 8 components. You can download Indy 9.x from http://www.nevrona.com/Indy

Before installing Indy 9.x, you must remove Indy 8 that was installed with Delphi 6. You can do this in Add/Remove Programs. You just modify your Delphi 6 instalation and remove Indy packages from the install list. Complete instalation notes for D6 are on the Indy download page (http://www.nevrona.com/Indy/download90.html).

For a start, you only need to download Indy 9.0.3 Automated NetInstall at http://www.nevrona.com/Indy/downloads/9_00_03/IndyNet9_00_03.EXE

When you have successfuly installed Indy, just use my previous directions for the timeout.

If you get the error at Connect, just connect with a timeout parameter set, for ex.

idTCPClient1.Connect(3000);  //3 sec. timeout
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Introduction Raise your hands if you were as upset with FireMonkey as I was when I discovered that there was no TListview.  I use TListView in almost all of my applications I've written, and I was not going to compromise by resorting to TStringGrid…
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…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

757 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

20 Experts available now in Live!

Get 1:1 Help Now