Professional Documents
Culture Documents
Contents
[hide]
1 Description
2 Code
3 Uses
Description
This example builds a Chat Room using sockets components. To build the example, follow the instructions:
3. In the Project Manager, right-click ProjectGroup1 > Add New Project and add a new VCL Forms Application. Save it as Client.
4. Add two buttons (Send and Start/Stop), a memo box, an edit box, and a TServerSocket from the Tool Palette to the Server form.
5. Add two buttons (Send and Connect/Disconnect), a memo box, an edit box, and a TClientSocket from the Tool Palette to the Client form.
Code
6. In Server.pas
1. Add to the TForm1 class a private variable, Str, of type String, in which to save the messages received or sent by the server.
2. Add the code below to the OnClick event of the Start button:
7. In Client.pas
1. Add to the TForm2 class a private variable, Str, of type String, in which to save the messages received or sent by the client.
2. Add the code below to the OnClick event of the Connect button:
16. Add the code below to the OnClick event of the Send button:
3. Start the Server by pressing the Start button from the server form.
4. Connect the Client by pressing the Connect button from the client form.
5. Start sending messages from server to client, and from client to server.
Uses
System.Win.ScktComp.TServerSocket
System.Win.ScktComp.TClientSocket
See Also