import java.io.*;
import java.net.*;
public class EchoClient {
private String ip;
private int port;
private String str;
BufferedReader file;
public EchoClient(String ip, int port) throws IOException {
this.ip = ip;
this.port = port;
Socket tcpSocket = getSocket();
OutputStream os_socket = tcpSocket.getOutputStream();
InputStream is_socket = tcpSocket.getInputStream();
BufferedWriter bufferW = new BufferedWriter(
new OutputStreamWriter(os_socket));
BufferedReader bufferR = new BufferedReader(
new InputStreamReader(is_socket));
System.out.print("입력 : ");
file = new BufferedReader(
new InputStreamReader(System.in));
str = file.readLine();
str += System.getProperty("line.separator");
bufferW.write(str);
bufferW.flush();
str = bufferR.readLine();
System.out.println("Echo Result : " + str);
file.close();
bufferW.close();
bufferR.close();
tcpSocket.close();
}
public Socket getSocket() {
Socket tcpSocket = null;
try {
tcpSocket = new Socket(ip, port);
} catch (IOException ioe) {
ioe.printStackTrace();
System.exit(0);
}
return tcpSocket;//
}
public static void main(String[] args) throws IOException {
new EchoClient("117.17.72.202", 3000);
}
}
'콩's EDUCATION > 콩's JAVA_RUN' 카테고리의 다른 글
기본형 변수 최소, 최대값 (0) | 2014.05.07 |
---|---|
클라이언트 연결 3 (0) | 2013.07.17 |
클라이언트 접속 (0) | 2013.07.17 |
10진수, 2진수, 8진수, 16진수로 쉽게 바꾸기 (0) | 2013.06.27 |
클래스 연습 (중요) (0) | 2013.06.26 |