- Start Borland C++ Builder with the default form
- From the Standard tab of the Component Palette, add an Edit control
- From the Internet tab of the Component Palette, click the ServerSocket button and click on the form:
- Double-click an empty area on the form to access its OnCreate event
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ServerSocket1->Port = 23;
ServerSocket1->Active = True;
}
//---------------------------------------------------------------------------
|
- On the Events tab of the Object Inspector, double-click the event of
the OnClose field and implement it as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
ServerSocket1->Active = False;
}
//---------------------------------------------------------------------------
|
- On the form, click the ServerSocket1 control
- On the Events tab of the Object Inspector, double-click the
OnClientRead event
- Implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::ServerSocket1ClientRead(TObject *Sender,
TCustomWinSocket *Socket)
{
Edit1->Clear();
Edit1->Text = Socket->ReceiveText();
}
//---------------------------------------------------------------------------
|
- Save the project as Communication1 in a new folder named
Communication1
- To create the application so it can execute on another computer, on
the main menu, click Project -> Options...
- Click the Linker tab
- Uncheck the Use Dynamic RTL check box
- Click the Packages tab
- Uncheck the Build With Runtime Packages check box
- Click OK
- Save everything
- Press F9 to execute the application
- Distribute the application to the computer that will receive the
message. It is small enough so you can copy it to a floppy disk or you
can put it in a shared directory
- Get the IP address of the computer you will send the messages to.
You can go to the computer or ask somebody to get it. You can get the
IP address at the Command Prompt by typing ipconfig and
pressing Enter. Write that IP address down
- Start a new C++ Builder with the default form
- Save the project in a new folder
- From the Standard tab of the Component Palette, add an Edit control
and a Button. Change the Caption of the button to &Send
- From the Internet tab of the Component Palette, click the
ClientSocket button and click on the form:
- Double-click an empty area on the form to access its OnCreate event
- Implement it as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormCreate(TObject *Sender)
{
ClientSocket1->Port = 23;
ClientSocket1->Host = "Type the Above IP Address Here";
ClientSocket1->Active = True;
}
//---------------------------------------------------------------------------
|
- On the Events tab of the Object Inspector, double-click the event of
the OnClose field and implement it as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::FormClose(TObject *Sender, TCloseAction &Action)
{
ClientSocket1->Active = False;
}
//---------------------------------------------------------------------------
|
- On the form, double-click the button control and implement the event as follows:
//---------------------------------------------------------------------------
void __fastcall TForm1::Button1Click(TObject *Sender)
{
if( ClientSocket1->Active )
ClientSocket1->Socket->SendText(Edit1->Text);
}
//---------------------------------------------------------------------------
|
- Save the project.
- Execute the application. Type some text and click Send
|
|