I am working on a small chat program for one of my classes, where users can connect to a server and create groups to chat in. When the user connects a new thread is created for the user-server to interact in, inside this thread I add a user to a list of users that have already connected. I am running into the issue an where inside my thread I am adding a user to the list of users but for some reason when I check to the number of users that have connected on my client program code, is says the number of users is 0.
Sorry for the long post, any help would be awesome.
"If the facts don't fit the theory, get new facts" --Albert Einstein
Every time you type in your console: java className, a new JVM is started. I wouldn't classify this as a problem. You can run your programs in a single JVM but that isn't really the idea behind communicating through sockets. You could ask the server what the number of users is at that time and print that.
The server has a method getClients() which returns a List of all the clients connected to the server. The size of that list should be the number of clients that connected to the server, so when I call that method and test it's size isn't that the same as asking the server for the number of users?