Socket echoSocket = new Socket(hostName, portNumber);
final PrintWriter out = new PrintWriter(echoSocket.getOutputStream(), true);
BufferedReader in = new BufferedReader(
new InputStreamReader(echoSocket.getInputStream()));
new Thread() {
public void run() {
while(true) {
out.println ("hello");
try {
Thread.sleep(60*1000);
} catch(Exception e) {}
}
}
}.start();
String input;
while ((input= in.readLine()) != null) {
System.out.println("echo: " + input);
}
你是要做心跳包么有一些好的框架可以用的啊