I have two methods in server and in client:
Server:
@Override
public void start(Stage primaryStage) throws Exception {
socket = new Socket("localhost", 9998);
System.out.println("connected");
input = new ObjectInputStream(socket.getInputStream());
System.out.println("1");
output = new ObjectOutputStream(socket.getOutputStream());
output.writeObject(new Message(CONFIG, "ping"));
FXMLLoader loader = new FXMLLoader(this.getClass().getResource("/window/fxmls/window.fxml"));
loader.setController(this);
AnchorPane anchorPane = loader.load();
Scene scene = new Scene(anchorPane);
primaryStage.setScene(scene);
primaryStage.show();
}
Client:
@Override
public void run() {
try {
serverSocket = new ServerSocket(9998);
while (true) {
Socket socket = serverSocket.accept();
System.out.println("connected");
input = new ObjectInputStream(socket.getInputStream());
System.out.println(1);
output = new ObjectOutputStream(socket.getOutputStream());
Message message = (Message) input.readObject();
if (message.getHeader() == CONFIG && message.getMessage().equals("ping")) {
System.out.println(message.getMessage());
}
}
} catch (IOException | ClassNotFoundException e) {
e.printStackTrace();
}
}
When client is start running, sends checking message "ping
" using ObjecInputStream, but code in above methods is stopping on System.out.println(1);
I don't know why. Before in similar code all was running. What I did bad? input = new ObjectInputStream(socket.getInputStream());
is waiting for something what I haven't done?