My client server bytearray sending message to client is not being received by client
<p>I am having problems with my server/client sending a bytearray output buffer to client. The client is never receiving the messaage when it gets to ByteArrayInputStream bas = new ByteArrayStream().readByteArrayInputStream( in);
I am not sure why and it is driving me crazy. This code compiles and runs from the main thread. it start server waits a while starts cient waits a while and then sends message from server to client. Please help! Thank you very mucy!!! Look and the send from the server where i convert for byte stream and where I'm reading in lci</p>

<pre><code>package comms;

import java.io.ByteArrayInputStream;
import java.io.ByteArrayOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectOutputStream;
import java.net.ServerSocket;
import java.net.Socket;
import java.net.SocketTimeoutException;
import java.net.UnknownHostException;

public class ServerClient {

public  ServerClient(){
    Server server = new Server();
    server.start();
    try {
        Thread.sleep(1000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
    new Client().start();

    try {
        Thread.sleep(3000);
    } catch (InterruptedException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }

    server.sendMessage("String");

}

public static void main(String[] args) {

    new ServerClient();

}


public final static int DEFAULT_SOCKET = 2004;


public class Server extends Thread {
    private int portNumber = DEFAULT_SOCKET;


    private ServerSocket providerSocket;
    private Socket connection = null;

    private ByteArrayOutputStream out;
    private InputStream inputStream;
    private boolean stopThread =false;

    private ByteArrayInputStream inStreamByteAray;

    public void run()
    {
        try{
        openServerSocket();

        if( connection!=null){

            out = new ByteArrayOutputStream();
                out.flush();

            inputStream = connection.getInputStream();

            //TODO add reading
            do{
                Thread.sleep(1000);
                // TODO add reading from client
            }while(!stopThread);
        }
    }
    catch(IOException ioException){
        ioException.printStackTrace();
    }
    catch(Exception e){
        e.printStackTrace();
    }
    finally{
        try{
            if(inputStream!=null){
                inputStream.close();
            }
            if(out!= null){
                out.close();
            }                       
            if(providerSocket!=null){
                providerSocket.close();
            }
        }
        catch(IOException ioException){
            ioException.printStackTrace();
        }
    }
}
public void openServerSocket(){

    try {
        providerSocket = new ServerSocket(portNumber, 20, IPAddress.getHostInetAddress() );
            connection = providerSocket.accept();
        } 
        catch(SocketTimeoutException  e){
            e.printStackTrace();
        }
        catch (IOException e) {
            e.printStackTrace();
        }
    }
    public void sendMessage(Object string)

    {
        try{
            if(out!=null){              
                out.write(serialize(string));
                out.flush();
            }
        }
        catch(IOException ioException){
            ioException.printStackTrace();
        }
    }

    public  byte[] serialize(Object obj) throws IOException {
        ByteArrayOutputStream b = new ByteArrayOutputStream();
        ObjectOutputStream o = new ObjectOutputStream(b);
        o.writeObject(obj);
        return b.toByteArray();
    }
}

public class Client extends Thread {
    private Socket requestSocket;
    private ByteArrayOutputStream out;
    private InputStream in;
    private boolean stopThread =false;
    private int portNumber = DEFAULT_SOCKET;
    public void run()
    {
        try{                
            openClientSocket();

            out = new ByteArrayOutputStream();
            out.flush();
            in = requestSocket.getInputStream();

            // Read message loop
            do{
                try{

                    ByteArrayInputStream bas = new ByteArrayStream().readByteArrayInputStream( in);
                }
                catch(IOException e){
                    e.printStackTrace();
                } 

            }while(!stopThread);
        }
        catch(UnknownHostException unknownHost){
        }
        catch(IOException ioException){
            ioException.printStackTrace();
        }
    }

    public void openClientSocket(){
        while(requestSocket==null){
            try {
            requestSocket = new Socket(IPAddress.getHostName(),portNumber );
            } catch (UnknownHostException e) {

            } catch (IOException e) {

            }
            if(requestSocket==null){
                try {
                    Thread.sleep(1000);
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            }

        }
    }
}
}
</code></pre>
