Hi guys,
So I made this thread to deal with my server problems!
First thing's first, in this guy's server code he has the following
do{//Start a do while loop while run is true
Socket newConnection = server.accept();//Check if we have a connection, if we do continue otherwise try again
String name = "guest"+ply;//Select an unique name for this player
Player p = new Player(name, newConnection);//Create a new Player instance and set the socket to it
System.out.println("New Player Connected from IP: "+newConnection.getInetAddress()+" and was assigned the name "+name);//Display the message that we got a new player
ep.execute(p);//Assign the player instance a thread
players.put(name, p);//Add the player instance to the player HashMap
}while (run);
At line 2 he commented, check if we have a connection and if we do continue otherwise try again..
I don't see an if statement, so how is he preventing line 3 and up from running if there isn't a connection ?
When I look up the .accept method it says this
Listens for a connection to be made to this socket and accepts it. The method blocks until a connection is made.
when it says block does that mean the code wont read past line 2 until a connection is made ?
↧