Hey daniweb!

I have a really serious issue in my program right now.

I'll explain how this piece works:
-The server sends a ping
-The client replies with a pong and starts a timer
-Server sends pong back and the client checks how long it took to receive the second pong (Latency check)

Right now the client is spaming pong to the server without delay. I think this is the case because when i shut down the client the server acts as normal without mass errors.

The clients code:

import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.PrintStream;
import java.net.Socket;

import javax.swing.Timer;

public class dataIn implements Runnable, ActionListener {
	static BufferedReader in;
	static String ex1;
	Boolean threadcontinue = true;
	static String o;
	static String o1;
	Socket s;
	Timer t1 = new Timer(1, 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()));
				System.out.println("dataIn started.");
				while(threadcontinue) {
					in = new BufferedReader(new InputStreamReader(s.getInputStream()));
					ex1 = in.readLine();
					if(ex1.equalsIgnoreCase("ping")==true) {
						System.out.println("received ping");
						PrintStream pstream2 = new PrintStream(s.getOutputStream());
						System.out.println("pong sent!!");
					} else if(ex1.equalsIgnoreCase("pong")) {
						System.out.println("received pong");
						System.out.println("Latency: " + PingTime + "ms.");
						ClientApplet.io1 = PingTime + " ms.";
						PingTime = 0;
		} catch (Throwable t) {
				// TODO Auto-generated catch block

	public void actionPerformed(ActionEvent e2) {
		// TODO Auto-generated method stub
		if (e2.getSource() == t1) {
			PingTime = PingTime + 1;
			if(PingTime > 10000) {
				System.out.println("t1 stopped");

What's the issue with it sending pong so much?
ex1 is the variable holding the socket data. I tried starting from there but couldn't find anything :s

Thank you so so much in advance

7 Years
Discussion Span
Last Post by Olliepop

Hey guys, i solved this. Turns out the error wasn't in here at all! It was in the server! I declared the socket variable before the while loop instead of inside it (like it is in the code above) so therefore the value wasn't changing and was instead in an infinite loop :)

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.