我过去每 3 秒TimerTask
发送一次消息,但它只发送一次。
public static void main(String[] args) throws IOException {
soc = new Socket("localhost", 12345);
out = new PrintWriter(soc.getOutputStream(), true);
send();
}
private static void send() {
Timer timer = new Timer();
timer.schedule(new TimerTask() {
@Override
public void run() {
out.println("fetewtewwefwfewf egreg \n");
out.flush();
InputStream is;
try {
is = soc.getInputStream();
DataInputStream dis = new DataInputStream(is);
while (!soc.isClosed()) {
long value = dis.readLong();
System.out.println(value);
}
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}, 3000);
}
}