客户端

public class TestClient {

public static void main(String[] args) {
// TODO Auto-generated method stub
System.out.println("请输入你要发送的消息:");
String msg = new Scanner(System.in).next();
Socket client = null;
try {
client = new Socket("192.168.1.212", 9527);

// OutputStream out = client.getOutputStream();
// out.write(msg.getBytes());
// out.flush();

BufferedWriter bw = new BufferedWriter(new OutputStreamWriter(client.getOutputStream()));
bw.write("张三&" + msg + "&" + System.currentTimeMillis());
bw.flush();
} catch (UnknownHostException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} finally{
if(client != null){
try {
client.close();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
}

}

posted @ 2016-06-19 17:10  钟振杰  阅读(175)  评论(0编辑  收藏  举报