Right now your client is not sending anything, let alone an object. So there is nothing to flush.
You will also need to resolve some synchronization problems. As it is right now, you have a lock. The server is not sending the "test string" object because it is waiting for the client to send a serialized object (since the ObjectInputStream is blocking). Meanwhile, the client is waiting for the server to send something (i.e. the "test string"). So each side is waiting for the other to send something.
To resolve this, in the server code, you need to move the creation of the ObjectInputStream to after you send the "test string". This will allow the client to receive the
test String. If you run the code like this, you will see the client receive and print out the test String. The server will start to create the ObjectInputStream. The ObjectInputStream constructor blocks (i.e. waits) for the client to send an object. But then at this point, the client code is finished, so it exits. Upon doing so, the socket connection and its underlying streams close and the server will throw a java.net.SocketException.
So we now need to have the client send an object. So in the client, after it receives and prints out the object it receives form the server, have it send an object. Below is your code modified as an example:
This will:
1) have the server send a String object to the client;
2) the client receive and print it;
3) the client sends a Date object to the server;
4) the server receives and prints out the received object;
5) the client disconnects and the server waits for another connection.
If that's OK, then great. But if you need more flexibility in terms of which side sends what when, you'll need to put some more logic around things. For example have one or the other side send a "command" to tell the other, "I want to send you an object. Are you Ready?" The other side then needs to acknowledge and get ready to receive the object. So basically, you need to determine a protocol for your client and server to communicate. If you want to get past anything but a very stringent a-b-c-d like protocol where things are always done in the exact same order, you will likely want to (or need to ) multi-thread things. It's a fun exercise to make such things.
I hope that helps.