Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 734
  • Last Modified:

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

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
Prof_MAM
Asked:
Prof_MAM
  • 3
1 Solution
 
shaneholmesCommented:

 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
 
shaneholmesCommented:
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
 
Prof_MAMAuthor Commented:
then tell me how to keep trying until Connection happens
0
 
ceoworksCommented:
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
 
shaneholmesCommented:


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

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now