Using client.connect and Client.println and Java Sockets

Hi Folks, looking for some assistance. I am currently using some of the test code with some small modifications to test the client.connect and client.println…specifically…

 if (client.available())
    Serial.println("Inside Loop function now");
    for (int i=0;i<50;i++) {
        Serial.println("Just sent a print to client connection");

On my local server, I have the following small java server listening and ready to accept the data from this as follows:

 while ((inputLine = in.readLine()) != null) {
		                System.out.println("Valueof inputline is " + inputLine);
		                try {	Thread.sleep(1000);
							catch(Exception e)

where in is a bufferedreader on the inputstream.

The issue I am having is that the first two printlns come across fine (in the future it will be sensor data) but after two (sometimes 3 and sometimes 4), I get a socket exception…Exception caught when trying to listen on port 6666 or listening for a Software caused connection abort: recv failed
Software caused connection abort: recv failed
I have used this small section of code before without difficulty so I’m wondering if my understanding of the println is correct…should I be using write instead?

Thanks for any help,

So, quick update. I’m not entirely sure why but I decided to take the For loop out of the code above (seemed redundant given the core loops continuously anyway) and I moved the “out.println” before the While loop in the Java Code and voila, it started working.

I now have a slight different issue…if you notice above there are “serial.println” statements that I have been using to debug. If I take these out (remove everything related to the serial connection), the core does not seem to run the code as before…nothing happens, no connection via wifi?

Am I missing something?