Even better server resource management
This commit is contained in:
@@ -31,12 +31,9 @@ public class Room
|
||||
//tells players turn (array index)
|
||||
private int currentPlayer = 0;
|
||||
|
||||
private long timeOut = 0;
|
||||
private Timer t;
|
||||
|
||||
public Room(String roomCode, Server server)
|
||||
{
|
||||
timeOut = System.currentTimeMillis();
|
||||
|
||||
this.roomCode = roomCode;
|
||||
startPositions = new Vector3[4];
|
||||
@@ -56,8 +53,6 @@ public class Room
|
||||
*/
|
||||
public void addClient(Client client)
|
||||
{
|
||||
//the timeout variable for a single player
|
||||
timeOut = System.currentTimeMillis();
|
||||
|
||||
//loops through all players existing and sends the needed information
|
||||
for (int i = 0; i < players.length; i++)
|
||||
@@ -100,9 +95,6 @@ public class Room
|
||||
//read the data to the buffer
|
||||
input.read(readData);
|
||||
|
||||
//reset the timeout once something is received
|
||||
timeOut = System.currentTimeMillis();
|
||||
|
||||
|
||||
/*
|
||||
----------------------------------------
|
||||
@@ -407,12 +399,5 @@ public class Room
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
try
|
||||
{
|
||||
t.cancel();
|
||||
} catch (Exception e)
|
||||
{
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +52,8 @@ public class Server
|
||||
System.out.println("Client connected!");
|
||||
|
||||
//create a new thread for the connected client to free up main thread resources for new connections
|
||||
Thread t = new Thread(new Runnable()
|
||||
Thread t = null;
|
||||
t = new Thread(new Runnable()
|
||||
{
|
||||
@Override
|
||||
public void run()
|
||||
@@ -81,6 +82,9 @@ public class Server
|
||||
/**
|
||||
* !!!!!!!!!!!!!!!!!!! 0 is not used because of possible empty arrays read in because of inital connection errors !!!!!!!!!!!!!!!!!!!!
|
||||
*/
|
||||
case 0:
|
||||
Integer.parseInt("crash");
|
||||
break;
|
||||
|
||||
//this case generates a new room and sends the room code to the requester (not for join)
|
||||
case 2:
|
||||
@@ -139,6 +143,8 @@ public class Server
|
||||
break;
|
||||
}
|
||||
|
||||
System.out.println("Init Thread finished");
|
||||
|
||||
} catch (Exception e)
|
||||
{
|
||||
System.out.println("Client disconnected!");
|
||||
|
||||
Reference in New Issue
Block a user