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


이 블로그의 인기 게시물

좌표 변환: 회전 이동

Unmappable character for encoding MS949

Hello JNI (3), C 라이브러리에 문자열 전달