标签:
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