package com.itjob.javanetwork;

import java.io.*;
import java.net.*;

/**
 * 客户端Socket类
 * @author AmigoXie
 */
public class Client {
	Socket socket;
	BufferedReader in;
	PrintWriter out;

	public Client() {
		try {
			// 连接服务器端的Scocket
			socket = new Socket("127.0.0.1", 10000);
			// 读取输入字符，输出到服务端Socket中
			System.out.println("Please enter some Character:");
			BufferedReader line = new BufferedReader(new InputStreamReader(System.in));
			out = new PrintWriter(socket.getOutputStream(), true);
			out.println(line.readLine());
			// 读取从服务端Socket输入的信息
			in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
			System.out.println(in.readLine());
			
			// 关闭资源
			out.close();
			in.close();
			socket.close();
		} catch (IOException e) {
			e.printStackTrace();
		}
	}

	public static void main(String[] args) {
		new Client();
	}
}
