Socket Sample: Chat Client

Introduction

This is the "Socket" project. In the project directory there is an executable file "Server Socket.exe". You will need to run this program on the server machine in order to try the "Socket" sample.

You need a machine with TCP/IP protocol installed but not necessarily a connection to the internet (in which case you must chat with yourself). One machine will be the Chat server and one or more machines (possibly the same as the server) will be the Chat clients.

On the server, run the "Server Socket" program. The server is now ready for a chat session.

On each client, run the "Socket" applet. The first thing a client must do is connect to the server. If you are connecting to a server on a different machine, you will have to change the default value in the "Server" text box to the chat server's internet address. To connect to the server, click the "Connect" button. Type in lines of text, then click the "Send" button. The server will echo the lines back to all clients in the chat session. When you are finished chatting, click the "Disconnect" button. To erase the message log, click the "Clear" button.

To shut down the chat server, click the "Stop" button.

Socket Features Demonstrated by the Chat Client

The Socket project uses an asynchronous socket. An asynchronous socket triggers events to coordinate actions on the socket. For example, an event is triggered when data arrives on the socket, or when the host name is resolved. The properties and events of the socket can be seen by clicking on the socket icon on the form.