客户端

时间:2016-06-19 18:15:15   收藏:0   阅读:149

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
© 2014 bubuko.com 版权所有 - 联系我们:wmxa8@hotmail.com
打开技术之扣,分享程序人生!