//SimpChatClient.java //send messages to server import java.net.*; import java.io.*; import javax.swing.*; public class SimpChatClient { public static void main( String[] args ) throws IOException, ClassNotFoundException { Socket client; //for convenience of send/receive objects, primitives: ObjectInputStream input; ObjectOutputStream output; String transMsg, recvMsg; //String serverName = "127.0.0.1"; //localhost //String serverName = "192.168.1.101"; String serverName = JOptionPane.showInputDialog("Enter IP address of the server"); //make connection attempt to IP, port do{ client = new Socket( InetAddress.getByName( serverName ), 12345 ); System.out.println( "Client made connection to: " + client.getInetAddress().getHostName() ); //output stream for objects output = new ObjectOutputStream( client.getOutputStream() ); output.flush(); input = new ObjectInputStream( client.getInputStream() ); //client will send first transMsg = JOptionPane.showInputDialog("CLIENT: Enter message"); output.writeObject( transMsg ); output.flush(); //? //then receive recvMsg = (String)input.readObject(); //JOptionPane.showMessageDialog(null, "Client received: " + message ); System.out.println( "Client received: " + recvMsg ); } while (!transMsg.equals("QUIT")); input.close(); output.close(); } }