package server;

import java.io.*;
import java.net.*;
import java.util.Vector;
import java.lang.Math;
import client.Client;

public class Server {
	private ServerSocket ss;
    
    public static void main(String[] args){
        Server si = new Server();
        si.startServer();
    }

    public Server(){
        try{
            ss = new ServerSocket(30001);
            System.out.println("Server booting...");
        }catch(IOException ioe){ioe.printStackTrace();}
    }

    public void startServer(){
        Socket connection;
        Statebox mb = new Statebox();
        UpdateToClient rt = new UpdateToClient(mb);
        rt.start();
        try{
            while(true){
                connection = ss.accept();
                new PlayerParticipant(connection, mb).start();
                rt.addSocket(connection);
            }
        }catch(IOException ioe){ioe.printStackTrace();}
    }
}

class UpdateToClient extends Thread{
    private Statebox statebox;
    private byte[] msg;
    private Vector<Socket> clients;
    private Writer writer;

    public UpdateToClient(Statebox statebox){
        this.statebox = statebox;
        this.clients = new Vector<Socket>();
    }

    public void addSocket(Socket s){
    	clients.add(s);
    }
    
    public void run(){
        while(true){          
            msg = this.statebox.readMessage();    
            
            if(!(msg.length < 2)){
                for(int i = 0 ; i < clients.size(); i++){
                	try{
                        writer = new OutputStreamWriter(clients.get(i).getOutputStream()); 
                        writer.write(msg.toString(), 0, msg.length);
                        writer.flush();
                	} catch(IOException ioe){
                		ioe.printStackTrace();
                	}
                }
            }
        }
    }
}

@@ -95,16 +95,17 @@
 g.Math;%0A
+%0A
 import c
@@ -1047,22 +1047,28 @@
 private 
-Writer
+OutputStream
  writer;
@@ -1540,31 +1540,8 @@
 r = 
-new OutputStreamWriter(
 clie
@@ -1568,17 +1568,16 @@
 Stream()
-)
 ; %0A     
@@ -1615,34 +1615,8 @@
 (msg
-.toString(), 0, msg.length
 );%0A 

change to outputstream