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!