Hey guys :)
I am stuck on this piece of code i am about to give below. What happens, is the server sends a "ping" to the client, the client sends "pong" back, but when the server sends "pong" back to the client (i KNOW this is sent) the client doesn't pick it up.
dataIn is a thread started on the client.
Are there any errors you guys pick up here?
This thread is started from an applet,
The part where "pong" should be picked up by the client is
} else if(in.readLine().equalsIgnoreCase("pong")) {
t1.stop();
System.out.println("Latency: " + PingTime + "ms.");
PingTime = 0;
}
This is the full class code:
public class dataIn implements Runnable, ActionListener {
static BufferedReader in;
Boolean threadcontinue = true;
static String o;
static String o1;
Socket s;
Timer t1 = new Timer(10, this);
public static int PingTime = 0;
dataIn(Socket s) {
this.s = s;
}
public void run() {
// TODO Auto-generated method stub
try {
in = new BufferedReader(new InputStreamReader(s.getInputStream()));
try {
while(threadcontinue==true) {
if(in.readLine().equalsIgnoreCase("ping")==true) {
PrintStream pstream2 = new PrintStream(s.getOutputStream());
pstream2.println("pong");
t1.start();
System.out.println("pong sent!!");
} else if(in.readLine().equalsIgnoreCase("pong")) {
t1.stop();
System.out.println("Latency: " + PingTime + "ms.");
PingTime = 0;
}
}
} finally {
}
} catch (Throwable t) {
// TODO Auto-generated catch block
t.printStackTrace();
}
}
@Override
public void actionPerformed(ActionEvent e2) {
// TODO Auto-generated method stub
if (e2.getSource() == t1) {
PingTime = PingTime + 10;
System.out.println(PingTime);
if(PingTime > 100) {
t1.stop();
}
}
}
}
I would appreciate so much any insight possible, or even a solution. Thank you very much for your time!