World server

hi, I’m working on a world server.
I’m sturgeling with getting player’s already online and show them.
What I now do is create a worldsendThread (a listener for movement and connecting) and add it to a

List<worldsendThread>

then in the

public worldsendThread(Socket client){
//here i add the thread to a list
}

Here is the actual code:

	private Socket client;
	public static PrintWriter out;
	public static BufferedReader in;
	public WorldSendThread(Socket worldClient){
		this.client = worldClient;
		RealmWorldServer.clients.addThread(this);
	}
	
	
	@Override
	public void run(){
		try {
			 out = new PrintWriter(client.getOutputStream(),true);
			 in = new BufferedReader(new InputStreamReader(client.getInputStream()));
			String line = "";
			while ((line = in.readLine()) != null){
			System.out.println(line);
			Scanner sc = new Scanner(line);
			
			RealmWorldServer.clients.sendMessage("create player X 200 Y 200");
			
			
			}

			out.close();
			in.close();
		} catch (IOException e) {
			
			e.printStackTrace();
		}
		
	}
	
	
	public void sendMessage(String message){
		out.println(message);
	}

The problem is with this code, when I connect It draws a player without anyone else being that player.

Anybode knows how to solve this?

Thanks!

Your ‘in’ and ‘out’ variables are static, causing only the last player’s IO objects to be referenced :wink:

Thanks for the reply.

But it doesn’t seems to work,

I use this line

	 RealmWorldServer.clients.sendMessage("pc| |X| 200 |Y| 200");

to send to the client(player) a message that he needs to create a player a X 200 y 200

But I do that when the client runs what means that it just gona create a user.

The problem is that I don’t know how I should check all user’s on connected and then draw them all.

thanks!

Maybe you want to setup your own protocol of how to identify player IDs and their data.

so create a Player class and then when I go into the thread create a player and just send those paramaters via getters and setters?