Improve company productivity with a Business Account.Sign Up

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

Socket Question - Help Plz (Borland C++ Builder)

The following doesn't work as enable button:

MainClientSocket->Open ( );

  if ( MainClientSocket->Active )
  {
    MainMenuItem->OnClick = DisconnectMenuItemClick;
    MainMenuItem->Caption = "&Disable";

    MainStatusBar->Panels->Items [0]->Text = "Connected";
  }

how do I wait long enough for the clientsocket component to finish trying, because the active property is still set to false when it checks right away :/
0
Aeonin
Asked:
Aeonin
  • 7
  • 4
1 Solution
 
AeoninAuthor Commented:
A suggestion to do it in another way is great too.

I just need to open that socket, if it fails the event handler etc. of the connect button hould not change, if it succeeds the event handler and the caption need to change to the disconnect handler and caption.
0
 
AlexVirochovskyCommented:
If I understand right your problem, you want know, if
connection still active.
Try send message with 0 lenth. If this fails, connection closed (disable), else enable .
0
 
octiCommented:
Write to the OnError event handler of the MainClientSocket and update the caption there. If the error code is eeConnect, then the connection failed...so you can change the caption.
After handling the error, set the errorcode to no error.
Octi
0
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

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.

 
AeoninAuthor Commented:
No, the code is the event handler for the Connect button, which will make the ClientSocket connect to a specified address.

So, you click connect, it then opens the socket, but if I check the Active property right away it is still set to false, even if the client will connect or has connected, I dont know if it takes time.

Hmm, the onerror may be suitable, let me try.
0
 
octiCommented:
Please read again my comment...-:)
No need to check the Active property, because the OnError will occure after a connection failure.
So my answer is part of the chapter ..."suggestion to do it in another way" from your question.
0
 
AeoninAuthor Commented:
And no the OnError idea will not work, it must change  the handlers if it connects
0
 
AeoninAuthor Commented:
User> Clicks connect
Program> Opens (tries to anyways) the ClientSocket

Now the program must wait until it connects, or until it fails to connect, howww
0
 
AeoninAuthor Commented:
As you can see, the OnError will only occur if it fails, I cant change the button already to the other status, because someone might click on ít, it will have to wait for the connection
0
 
octiCommented:
1. Write to the OnConnecting event handler to disable the button. OnConnecting will occure after calling Open, but before the connection is established.
2. Write to the OnConnect event handler to change the caption in case of successful connetion, or
3. Write to the OnError event handler (check if eeConnect error was raised) to enable the connect button back, in case of connection failure.

This event will occure asynchrounisly, you don't have to worry about timing.

Octi
0
 
AeoninAuthor Commented:
Excellent, could you mind giving the same idea for a serversocket, since serversocket does not have an onerror, well, so it seems to me, the onlisten could be used for when a successfull listen, but as far as I know ports may not always be available and the server socket has a posibility of failing while trieing to claim a port.
0
 
octiCommented:
If the port is busy (a serversocket is already listening on the specified port) the Listen method (of the serversocket) will raise an exception.
So if you want to handle the unsuccessfull Listen, you have to write a try catch block for that.
e.g.

try{
   MainServerSocket->Active = true;
}
catch (...)
{
   ShowMessage("Port is busy");
}
0
 
AeoninAuthor Commented:
Found that out myself already, though borland keeps throwing an error screen even though I catch it, blegh, why didnt borland just add an onerror handler, i can tstand things like this :P

And while you are here.

A TControlBar, a TToolBar and a few autosized buttons on the toolbar,the toolbar is flat and showcaptions.

The point is I want the toolbar to be just as big as the buttons, now I can do that by manually setting the width to that, it displays fine in borland c++ builder, bun when you run it it lets disappear the last button or buttons. Even though the buttons are autosized thus fitting it  checks to display or not diplay them on their non-autosized width.

I also send trhis to borland with a huge list of other errors(still not fixed in bcb6 either too) but never got a response.

Is there anything I forgot?
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

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.

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