码迷,mamicode.com
首页 > 其他好文 > 详细

客户端

时间:2016-06-19 18:15:57      阅读:103      评论:0      收藏:0      [点我收藏+]

标签:

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

}

客户端

标签:

原文地址:http://www.cnblogs.com/zzj951103/p/5598381.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!