Scanner sc = new Scanner(System.in);
소켓은 인스턴스 생성시 접속할 IP주소와 포트번호가 필요하다
소켓 생성시 서버가 올바르다면 접속이 완료된다
try(
Socket s = new Socket("192.168.0.1", 9090);
) {
try (
PrintStream out = new PrintStream(s.getOutputStream());
BufferedInputStream in = new BufferedInputStream(s.getInputStream());
) {
System.out.println(new String(in.readAllBytes()));
while (true) {
out.println("> ");
out.println(sc.nextLine());
}
}
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}