Question: I'm developing a simple chat application that has a server and a client. I wanna use only one socket object in run-time. Example(Java Client) :

```
class POClient
{
    Socket socket;
    BufferedWriter out;

    POClient()
    {
        socket = new Socket("192.168.1.3", 4445);
        OutputStreamWriter osw = new OutputStreamWriter( socket.getOutputStream());
        out = new BufferedWriter(osw);
    }

    void SendMessage()
    {
        out.write("Hello");
        out.flush();//edit
        // On this line, I need to use out.close() but if I close it, also 
        // socket will be closed. I don't wanna this. I wanna use only one instance.
    }
}

```

C# Server : 

```
TcpClient client = listener.AcceptTcpClient();  //if a connection exists, the server will accept it

            StreamWriter writer = new StreamWriter(client.GetStream());
            StreamReader reader = new System.IO.StreamReader(client.GetStream());
            try
            {
                string line = "";
                while (true)
                {

                    line = reader.ReadToEnd();

                }
            }

```

If I don't use out.close(), 'reader' is waiting until out.close()

Where am I failing?

Answer: 
Try using `StreamReader.ReadLine()` instead of `StreamReader.ReadToEnd()`, and before `out.flush()` add `out.newLine()`. This should write each message in new line and read from stream by lines.
I think that you need to call `out.flush()`. 

The point of a `BufferedWriter` is that it writes data to an in memory buffer, and only sends it to the actual socket when the buffer is full or `flush()` is called. This is for performance reasons, for example it's much more efficient to make a bunch of calls to put small bits of data into the `BufferedWriter` and then make a single call to `send` on the socket to actually send it out on the network. Note that it works when you call `out.close()` because the `close` method flushes the writer before closing the underlying stream.