Server
1 ServerSocket serverSocket = new ServerSocket(1234);
2 while(true) {
3 Socket socket = serverSocket.accept();
4 InputStreamReader isr = new InputStreamReader(socket.getInputStream());
5 BufferedReader br = new BufferedReader(isr, 512);
6 String data = br.readLine();
7 br.close();
8 }
Client
1 InetAddress addr = InetAddress.getByName("...");
2 Socket socket = new Socket(addr, 1234);
3 OutputStreamWriter osw = new OutputStreamWriter(socket.getOutputStream());
4 BufferedWriter bw = new BufferedWriter(osw, 512);
5 PrintWriter pw = new PrintWriter(bw);
6 pw.println("Hello");
7 pw.flush();
8 pw.close();
댓글
댓글 쓰기