Free Trial

Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.


  • Create BookmarkCreate Bookmark
  • Create Note or TagCreate Note or Tag
  • DownloadDownload
  • PrintPrint

Writing a Chat Client

We’ll write the Chat client application in two stages. First we’ll make a send-only version that sends messages to the server but doesn’t get to read any of the messages from other participants (an exciting and mysterious twist to the whole chat room concept).

Then we’ll go for the full chat monty and make one that both sends and receives chat messages.

Version One: send-only

image with no caption

Note

Type a message, then press ‘Send’ to send it to the server. We won’t get any messages FROM the server in this version, so there’s no scrolling text area.

Code outline

public class SimpleChatClientA {

   JTextField outgoing;
   PrintWriter writer;
   Socket sock;

   public void go() {
        // make gui and register a listener with the send button
        

  

You are currently reading a PREVIEW of this book.

                                                                                        

Get instant access to over
$1 million worth of books and videos.

  

Start a Free Trial