I have a tcp socket sending three lines like this
out2.println("message1\n");
out2.println("message2\n");
out2.println("message3\n");
and another tco socket receiving and displaying these messages like this
System.out.println(in.readLine());
System.out.println(in.readLine());
System.out.println(in.readLine());
but only the first message is recieved and displayed, anything I send after that is not.
edit: here is the code
private void buttonActionPerformed(java.awt.event.ActionEvent evt) {
try {
// TODO add your handling code here:
String ipAddress = ipTextArea.getText();
sourceSocket = new Socket(ipAddress,32323);
out = new PrintWriter(sourceSocket.getOutputStream(), true);
in = new BufferedReader(new InputStreamReader(sourceSocket.getInputStream()));
System.out.println(in.readLine());
System.out.println(in.readLine());
System.out.println(in.readLine());
} catch (UnknownHostException ex) {
Logger.getLogger(DESWashView.class.getName()).log(Level.SEVERE, null, ex);
} catch (IOException ex) {
Logger.getLogger(DESWashView.class.getName()).log(Level.SEVERE, null, ex);
}
}
cWashStations is also called from a button event:
public void cWashStations(){
Thread washThread = new Thread(){
@Override
public void run(){
try {
sSocket2 = new ServerSocket(32323);
Thread stationThread = new Thread(){
@Override
public void run(){
try {
washSocket = sSocket2.accept();
out2 = new PrintWriter(washSocket.getOutputStream(), true);
in2 = new BufferedReader(new InputStreamReader(washSocket.getInputStream()));
out2.println("hello from attendant3423\n\n");
out2.flush();
out2.println("hello from attendant3423\n\n");
out2.println("1");
while(running){
}
} catch (IOException ex) {
Logger.getLogger(DESAttendantView.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
stationThread.start();
} catch (IOException ex) {
Logger.getLogger(DESAttendantView.class.getName()).log(Level.SEVERE, null, ex);
}
}
};
washThread.start();
}