There is need to create a new thread for each connection. Thread should have function to write to socket even if it is in run() waiting for client input: String clientCommand = in.readLine(). The function update should meet this requirements and be able to write to socket using PrintWriter outWr but it seems to be null, even if setting it in thread constructor.
Cannot initialize PrintWriter outWr in constructor. After try construction outWr remains to be null. How to fix it?
public class Server {
public static void main(String[] args) {
...
ClientServiceThread cliThread = new ClientServiceThread(clientSocket, id++, auction);
...
}
public class ClientServiceThread extends Thread {
private PrintWriter outWr;
ClientServiceThread(Socket s, int clientID, Auction a) {
try {
PrintWriter outWr = new PrintWriter(new OutputStreamWriter(
m_clientSocket.getOutputStream()));
} catch (IOException e) {
e.printStackTrace();
}
}
public void run() {....; String clientCommand = in.readLine(); ... }
public void update(String msg){outWr.println(msg);}
Look at this code
In constructor you do not initialize class field but local reference
PrintWriter outWrChange it to