/* * Server2.java * * Created on March 6, 2006, 5:07 PM * * To change this template, choose Tools | Template Manager * and open the template in the editor. */ package headley.chat; import java.io.DataInputStream; import java.net.ServerSocket; import java.net.Socket; /** * * @author Headley WIlliamson */ public class Server2 { /** * Creates a new instance of Server2 */ public Server2() { } public void startServer() { try { ServerSocket ss = new ServerSocket(51234); while (true) { try { Socket socket = ss.accept(); System.out.println("Got a connection"); DataInputStream dis = new DataInputStream(socket.getInputStream()); while (true) { String text = dis.readUTF(); System.out.println("Received:" + text); } } catch (Exception ex) { System.out.println("client disconnected"); } } } catch (Exception ex) { ex.printStackTrace(); } } public static void main(String [] args) { new Server2().startServer(); } }