/** * This method sends CONNECT packet to server in order to get registered as a player client. In * this implementation, the first player is registered as the goalie; the communication protocol * allows making goalie registration even from different application; server must take care of * getting registered of only one goalie per team * * @param transceiver * @param tmpName * @param id * @param side * @param agentRole * @param formation */ protected void connectToServer( Transceiver transceiver, String tmpName, int id, char side, char agentRole, Formation formation) { // tell the server on what side this player is, his role, what his // real home position is and place all this in a data packet char teamside; String name; if (side == 'l') { teamside = ConnectData.LEFT; name = teamNameL; } else { teamside = ConnectData.RIGHT; name = teamNameR; } // System.out.println("My team : " + name ); ConnectData connectData = new ConnectData( ConnectData.PLAYER, teamside, agentRole, WorldData.getRealPosOrVel(teamside, formation.getHome(id)), name); Packet connectPacket = new Packet(Packet.CONNECT, connectData, address, port); // attach sender ID for debug purposes if (side == 'l') connectPacket.senderIDdebug = -id; else connectPacket.senderIDdebug = id; // send CONNECT packet to server try { transceiver.send(connectPacket); // System.out.println(tmpName + " sent connectPacket: " // + " addr: " + address + " port: " + port + " :::::: " // + connectPacket.writePacket() ); // wait for the acknowledging INIT message from the server transceiver.setTimeout(1000); return; } catch (IOException e) { // we get here if things are really bad System.out.println("player " + tmpName + " fails to send to server.\n" + e); return; } }