codice:
public class LineClient { //classe del client
private String ip;
private int port;
public LineClient(String ip, int port) {
this.ip = ip;
this.port = port;
}
public static void main(String[] args) {
LineClient client = new LineClient("127.0.0.1", 4747);
try {
client.startClient();
} catch (IOException e) {
System.err.println(e.getMessage());
}
}
public void startClient() throws IOException {
Socket socket = new Socket(ip, port);
System.out.println("Connection established");
Scanner socketIn = new Scanner(socket.getInputStream());
PrintWriter socketOut = new PrintWriter(socket.getOutputStream());
Scanner stdin = new Scanner(System.in);
try {
while (true) {
String inputLine = stdin.nextLine();
socketOut.println(inputLine);
socketOut.flush();
String socketLine = socketIn.nextLine();
/*turno=getTurno;
if(socketLine.equals(turno)){
}*/
System.out.println(socketLine);
}
} catch(NoSuchElementException e) {
System.out.println("Connection closed");
} finally {
stdin.close();
socketIn.close();
socketOut.close();
socket.close();
}
}
}