Safari Books Online is a digital library providing on-demand subscription access to thousands of learning resources.
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
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