So basically I have to make the server and client "Ping" and "Pong" back and forth to each other 10 times, using a command line argument. They compile, but I keep getting an ArrayIndexOutOfBoundsException, which I know means my numbers are wrong somewhere... I think. I've tried testing different numbers, but I can't get it to stop throwing the exception. Suggestions?

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

public class Ponger // SERVER
{
	public void go()
	{ 
        try 
		{
            ServerSocket serverSocket = new ServerSocket(24047);

            while(true) 
            {
                Socket sock = serverSocket.accept();
                PrintWriter writer = new PrintWriter(sock.getOutputStream());

                for (int i = 0; i < 11; i++) 
                {
                    System.out.println("Pong");
                    writer.flush();
                    writer.close();
	    	    }
            }
        }
	    catch (IOException ex)
   		{ 
    		ex.printStackTrace();
    	}
    }

		public static void main(String[] args)
		{ 
            int numPlays = Integer.parseInt(args[0]); // Tried 10 and 0, no luck
			Ponger ponger = new Ponger();
			ponger.go();
		}
}
Java Code:
import java.io.*;
import java.net.*;
import java.lang.*;
public class Pinger // CLIENT
{ 
    public void go()
    {
        try
        {
            Socket s = new Socket("127.0.0.1", 24047);                                  
            InputStreamReader streamReader = new InputStreamReader(s.getInputStream());     
            BufferedReader reader  = new BufferedReader(streamReader);                                
            PrintWriter writer = new PrintWriter(s.getOutputStream());
            
            for (int i = 0; i < 11; i++)
            {
                System.out.println("Ping");
                
                writer.flush();
                writer.close();
            }
        }
        catch (IOException ex)
        {
            ex.printStackTrace();
        }
    }

    public static void main(String[] args) 
    {
        int numPlays = Integer.parseInt(args[0]); // I tried 10 and 0, no luck
        Pinger pinger = new Pinger();
        pinger.go();
    }
}