I'm working on my first Server/Client Project in Java. It's still very Basic and I was able to Exchange some data between the Server and the Client program. Now I facing Trouble to reconnect once the Client has terminated the Connection.
I'm comfing from Visual Basic where I just would have had a timer and a boolean, checking if a Connection was established or not and eventually reset the socket.
I tried something similar in Java by Setting up a Start method and a Restart method and just checking in a Loop what's the Status of the boolean.
Unfortunately, eclipse keeps giving me the message that I cannot make a static reference to a non-static field. Now I'm totally lost.
Here's the server's code which works fine once but cannot be restarted.
package ComplexChatServer;
public class MainRoutine {
public Boolean boIsRunning;
public ConnectionHandlerS chsEins;
public Boolean boConnected = false;
public String strText;
public void StartRunning() {
boIsRunning = true;
chsEins = new ConnectionHandlerS();
chsEins.SocketListener();
}
public void ContinueRunning() {
boConnected = chsEins.getClientStatus();
if (boConnected == true) {
//System.out.println("Connected");
strText = null;
strText = chsEins.ReadInput();
if (strText != null && strText.isEmpty() == false) {
System.out.println("Loop");
System.out.println(strText);
strText = "";
boIsRunning = true;
}
else if (strText.equalsIgnoreCase("+++END+++")) {
boIsRunning = false;
System.exit(0);
}
}
else {
//System.out.println("Not connected");
}
}
public static void main (String [] args) {
int intRun;
while (true) {
if (boIsRunning = true) {
intRun = 1;
}
else {
intRun = 0;
}
switch (intRun) {
case 0:
StartRunning();
break;
case 1:
ContinueRunning();
break;
}
}
}
}