Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

program to create a connection

Status
Not open for further replies.

martintxo

Programmer
Jun 1, 2005
3
0
0
BR
Hello!
I´m trying to write a program that creates a tcp connection. For the server to wait for the client to connect I use the following code:

//Set the listening port
TcpServer1->LocalPort=StrToInt(ePort->Text);
//Try to listen;
TcpServer1->Listening;
//If the listen attempt succeeded
if (TcpServer1->Listening)
{
//Update the status bar
StatusBar1->SimpleText="Listening on port "+ ePort->Text;
//Set the application's listening flag
Listening=TRUE;
//Disable listen and connect buttons
bListen->Enabled=FALSE;
bConnect->Enabled=FALSE;
}
else
StatusBar1->SimpleText="Error-error-error...";
}

I´m doing something wrong because I always get the "Error-error-error..." message in the status bar. Does anybody know what I'm doing wrong. I have also tried with WaitForConnection but it doesn´t work or I don´t know how to make it work.
Thanks in advance.
Martintxo
 
code below may or may not help.

if the server port is active, its listening.
but perhaps you are using a different object than
TServerSocket, in that case I am sure I am of little
help.

Code:
void __fastcall TChatForm::ServerListenClick(TObject *Sender)
{
  ServerListen->Checked = !ServerListen->Checked;
  if (ServerListen->Checked && AsServer1->Checked)
  { 
     ServerSocket->Active = true;
     StatusBar1->Panels->Items[0]->Text = "Listening...";

     SpeedButton1->Enabled = false;
     ClientConnect->Enabled = false;
     DisconnectClient->Enabled = false;
     ListBox1->Items->Add (ConfigureForm->Edit1->Text + " (Server)");
     UserAddress->Add (ConfigureForm->ComboBox1->Items->Strings [0]);
  }
  else
  {
     if (ServerSocket->Active)
     {
        ServerSocket->Active = false;
        ListBox1->Clear ();
        ListBox2->Clear ();

        // initialize the chat array to empty
        for (x = 0; x < 20; x++)
            if (chatarray [x])
            {
                delete chatarray [x];
                chatarray [x] = NULL;
            }
     }

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

tomcruz.net
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top