java.net.ServerSocket

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();


댓글

이 블로그의 인기 게시물

자바 암호화 확장 (JCE) 관련 자바 1.8.0_151 이후 변경 사항

좌표 변환: 회전 이동

HTTP POST