Answer the question
In order to leave comments, you need to log in
How to make two threads in Java?
I can't solve the problem with the server. It is necessary that Input and Output be in different streams, but how to separate them into two different streams? I tried, but after running them I got this:
Exception in thread "Thread-1" Exception in thread "Thread-0" java.lang.NullPointerException
at server.ServerInput.run(ServerInput.java:21)
at java.lang.Thread.run(Thread.java:745)
java.lang.NullPointerException
at server.ServerOutput.run(ServerOutput.java:20)
at java.lang.Thread.run(Thread.java:745)
try {
server = new ServerSocket(SettingsServer.getPort(), SettingsServer.getMaxUsers());
while (true) {
connect = server.accept();
output = new ObjectOutputStream(connect.getOutputStream());
input = new ObjectInputStream(connect.getInputStream());
inObject = (String)input.readObject();
if (inObject.equals("<html><table><tr><td>&&&$server_recd;</td></tr></center></html>") == true) {
SettingsServer.CounterPlus();
}
if (inObject.equals("<html><table><tr><td>/server</td></tr></center></html>") == true) {
SettingsServer.CounterPlus();
sendData(SettingsServer.getInformation());
}
if (inObject != null && inObject.equals("<html><table><tr><td>&&&$server_recd;</td></tr></center></html>") == false && inObject.equals("<html><table><tr><td>/server</td></tr></center></html>") == false) {
SettingsServer.CounterPlus();
last_message.setText(inObject);
sendData("&&&$client_recd;");
}
inObject = null;
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
} catch (HeadlessException e) {
e.printStackTrace();
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Answer the question
In order to leave comments, you need to log in
Bad programming style:
Good programming style:
The code looks very doubtful. What are you trying to do? I advise you to look towards Netty if performance is important to you. You can't tell from your code what the problem is.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question