Hello all,

I have been working on a simple chat server for several weeks and have recoded the entire server twice now. I think that I am getting closer with the code I have now but I cannot find the source of my problem. The problem is whenever a client connects the server simply shuts down. All help is appreciated(Source code below).

Java Code:
import java.io.*;
import java.net.*;
import java.util.*;

public class Server {
    private static Vector<Socket> connections = null;
    private static ServerSocket sock = null;
    private static Socket curcon = null;
    private static int cnt = 0;
    public static void main(String[] args) {
        System.out.println("Copyright 2009 - 2011 Keith Morris");
        System.out.println("Server Starting...");
        try {
            sock = new ServerSocket(412);
            System.out.println("Server Started...");
            while (true) {
                curcon = sock.accept();
                add(curcon);
                cnt++;
                BufferedReader in = new BufferedReader(new InputStreamReader(curcon.getInputStream()));
                String line = in.readLine();
                while (line != null) {
                    send(line);
                    line = in.readLine();
                }
            }
        } catch (Exception e) {
            handleError(e,"Idle");
        }
    }

    public static boolean add(Socket con) {
        boolean wasAdded = false;
        for (int i = 0; i <= connections.size(); i++) {
           Socket conz = connections.get(i);
           if (!conz.equals(con) && i >= connections.size()) {
               connections.add(con);
               wasAdded = true;
           }
        }
        return wasAdded;
    }

    public static void send(String mes) {
         for (int i = 0; i < connections.size(); i++) {
             Socket con = connections.get(i);
             try {
                PrintWriter out = new PrintWriter(new BufferedOutputStream(con.getOutputStream()));
                out.print(mes);
             } catch (Exception e) {
                 handleError(e,"Send");
             }
         }
    }

    public static void handleError(Exception e, String location) {
        if (e instanceof IOException) {
            System.out.println("I/O Error at " + location);
            e.printStackTrace();
        } else if (e instanceof SocketException) {
            System.out.println("Socket Error at " + location);
            try {
                sock.close();
            } catch (Exception ee) {
                System.out.println("Could not close socket please end the process \"java\"");
                ee.toString();
            }
            e.printStackTrace();
        }
    }
}
Sincerely,
Sari