I am building a client-server application using threading, but for some reason the `BufferedWriter` won't send the data out to the client through the socket.
I also get a `Socket Exception: Connection Reset` after running the client.
What am i missing?
Server:

```
public class Servernew {

protected String username;

protected ServerSocket serverSocket;

protected static LinkedList<ClientThreadNew> clients;

public static LinkedList<ClientThreadNew> getClients() {
    return clients;
}

public Servernew(int port) {
    try {

        serverSocket = new ServerSocket(port);

        clients = new LinkedList<ClientThreadNew>();
        System.out.println("Server is now running on port " + port);

        while (true) {

            Socket clientSocket = serverSocket.accept();

            ClientThreadNew clientThread = new ClientThreadNew(
                    clientSocket, username);

            clients.addLast(clientThread);

            clientThread.start();

        }

    } catch (IOException e) {
        // TODO Auto-generated catch block
        e.printStackTrace();
    }
}

public static void main(String[] args) { 

    new Servernew(4444);
}

```

}

ClientThread:

```
public class ClientThreadNew extends Thread implements Runnable {

protected String username;

public String getUsername() {
    return username;
}

public void setUsername(String username) {
    this.username = username;
}

protected Socket clientSocket;

protected BufferedReader inFromClientB;

protected BufferedWriter outToClient;

public ClientThreadNew(Socket clientSocket, String username)
        throws IOException {

    this.clientSocket = clientSocket;
    this.username = username;

    inFromClientB = new BufferedReader(new InputStreamReader(
            clientSocket.getInputStream()));

    outToClient = new BufferedWriter(new OutputStreamWriter(clientSocket.getOutputStream()));

}

public void run() {

    try {

        while (true) {

            String incomingMessage = inFromClientB.readLine();

            if (incomingMessage != null) {

                setUsername(incomingMessage);

                outToClient.write("hii");
                outToClient.newLine();
                outToClient.flush();

            }

        }
    } catch (IOException e) {
        System.out.print(e);

    }

}

```

}

ClientTest:

```
public class ClientTesst {
private static Socket socket;
private static BufferedWriter outToServer;
private String hostname;
private int portnum;
private static BufferedReader inFromServer;

public ClientTesst(String hostname, int portnum) throws IOException {
    this.hostname = hostname;
    this.portnum = portnum;

}

public void connect() throws UnknownHostException, IOException {

    socket = new Socket(hostname, portnum);
    System.out.println("Connection Established");
}

public String listUsers() throws IOException {

    inFromServer = new BufferedReader(new InputStreamReader(
            socket.getInputStream()));
    String listOfUsers = inFromServer.readLine().toString();

    return (listOfUsers);
}

public void sendMessage(String Msg) throws IOException {

    outToServer = new BufferedWriter(new OutputStreamWriter(
            socket.getOutputStream()));
    outToServer.write(Msg);
    outToServer.newLine();
    outToServer.flush();

}

public static void main(String[] args) throws Exception {

    ClientTesst x = new ClientTesst("localhost", 4444);
    x.connect();
    x.sendMessage("client x");

    ClientTesst y = new ClientTesst("localhost", 4444);
    y.connect();
    y.sendMessage("client y");
    y.listUsers();

}

```

}