public void run() //listening
    {

        print("listening port: " + port);
        while (true)
        {
            Socket s;
            ObjectInputStream input;
            ObjectOutputStream output;

            try
            {
                s = ss.accept();
                input = new ObjectInputStream(s.getInputStream());
                output = new ObjectOutputStream(s.getOutputStream());

                print("new connection");

                //readed all data
                int tableID = input.readInt();
                print("readed table ID: " + tableID);
                boolean joinAsPlayer = input.readBoolean();
                print("readed joinAsPlayer: " + joinAsPlayer);
                String nick = input.readUTF();
                print("readed nick: " + nick);
                String password = input.readUTF();
                print("readed password: " + password);
                //---------------

                if (!tables.containsKey(tableID))
                {
                    print("bad table ID");
                    output.writeInt(Connection_info.err_bad_table_ID.getValue());
                    output.flush();
                    continue;
                }
                Table table = tables.get(tableID);

                if (!jchess.MD5.encrypt(table.password).equals(password))
                {
                    print("bad password: " + jchess.MD5.encrypt(table.password) + " != " + password);
                    output.writeInt(Connection_info.err_bad_password.getValue());
                    output.flush();
                    continue;
                }

                if (joinAsPlayer)
                {
                    print("join as player");
                    if (table.isAllPlayers())
                    {
                        print("error: was all players at this table");
                        output.writeInt(Connection_info.err_table_is_full.getValue());
                        output.flush();
                        continue;
                    }
                    else
                    {
                        print("wasn't all players at this table");

                        output.writeInt(Connection_info.all_is_ok.getValue());
                        output.flush();

                        table.addPlayer(new SClient(s, input, output, nick, table));
                        table.sendMessageToAll("** Gracz " + nick + " dołączył do gry **");

                        if (table.isAllPlayers())
                        {
                            table.generateSettings();

                            print("Send settings to all");
                            table.sendSettingsToAll();

                            table.sendMessageToAll("** Nowa gra, zaczna: " + table.clientPlayer1.nick + "**");
                        }
                        else
                        {
                            table.sendMessageToAll("** Oczekiwanie na drugiego gracza **");
                        }
                    }
                }
                else //join as observer
                {

                    print("join as observer");
                    if (!table.canObserversJoin())
                    {
                        print("Observers can't join");
                        output.writeInt(Connection_info.err_game_without_observer.getValue());
                        output.flush();
                        continue;
                    }
                    else
                    {
                        output.writeInt(Connection_info.all_is_ok.getValue());
                        output.flush();

                        table.addObserver(new SClient(s, input, output, nick, table));

                        if (table.clientPlayer2 != null) //all players is playing
                        {
                            table.sendSettingsAndMovesToNewObserver();
                        }

                        table.sendMessageToAll("** Obserwator " + nick + " dołączył do gry **");
                    }
                }
            }
            catch (IOException ex)
            {
                Logger.getLogger(Server.class.getName()).log(Level.SEVERE, null, ex);
                continue;
            }
        }
    }