Solved

Checking if server is ready for connection (Clientsocket and server socket)

Posted on 2004-04-27
5
596 Views
Last Modified: 2010-04-05
I am using clientsocket and serversocket in aclient server application , I want the client to check if the server is ready and liesting before trying to connect to it . how to do that ??
0
Comment
Question by:Prof_MAM
  • 3
5 Comments
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10932630

 if ServerSocket.Active = True

TServerSocket listens for requests for TCP/IP connections from other machines, and establishes connections when requests are received, once the component is active...

 Shane
0
 
LVL 11

Accepted Solution

by:
shaneholmes earned 20 total points
ID: 10932659
oops sorry, i missed the first part.... "I want the client to check"

There is no way to determine if the remote host (Server) is active from the Client.

 You just keep trying to connect until successful or a condition has been made... (example: time)


Shane

1
 

Author Comment

by:Prof_MAM
ID: 10940247
then tell me how to keep trying until Connection happens
0
 
LVL 4

Expert Comment

by:ceoworks
ID: 10940977
Hi,

If your client and server programs is working in the same network, you may wants to choose to multicasting. With it, when your server connected, it can send multicast message to the network and when your client(which is listening multicast packages..) get this message, you can know that your server is available for to connect. Another advantage of this model is, your clients doesn't needs to know about your server ip then. It can find it easily with sending a multicast package to the network and wait for server to reply and send it's IP.

If you have Indy components, you can use Indy's TIdIPMCastServer/Client components for to do that. If you don't have you can download from http://www.indyproject.org.

Kind Regards,

Oktay
0
 
LVL 11

Expert Comment

by:shaneholmes
ID: 10941177


in your OnError event of the CLientSocket would be the best place to do it i think

procedure TForm1.Button3Click(Sender: TObject);
begin
  ErrorCount := 0;
  ClientSocket.Active := true;
end;


procedure TForm1.ClientSocketError(Sender: TObject;
  Socket: TCustomWinSocket; ErrorEvent: TErrorEvent;
  var ErrorCode: Integer);
begin
  inc(ErrorCount);
  Memo1.Lines.Add (IntToStr(ErrorCount) + ' - ErrorCode: ' + IntToSTr(ErrorCode));
  { ignore error }
  ErrorCode := 0;
 if Error Count < 100 do
  ClientSocket.active := TRUE;
end;

Shane
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
FMX enumerated colours 2 84
Downloading email attachments 2 67
how to send memory stream from ics Client To ics server ? 11 79
CheckListBox usage 3 49
A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
The uses clause is one of those things that just tends to grow and grow. Most of the time this is in the main form, as it's from this form that all others are called. If you have a big application (including many forms), the uses clause in the in…
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: …
I designed this idea while studying technology in the classroom.  This is a semester long project.  Students are asked to take photographs on a specific topic which they find meaningful, it can be a place or situation such as travel or homelessness.…

932 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

9 Experts available now in Live!

Get 1:1 Help Now