phmenard
04-05-2010, 05:10 PM
I have a 3D multi player environment up and running quit well ... the problem I'm running into is how to send entire objects from a java coded red5 server to an actionscript client?? In my java red5 server I have a player object similar to the one below ...
public class Player extends Object{
public String name;
public String id;
public String xPos;
public String yPos;
public String zPos;
public String yRot;
public String direction;
public Player(String myName, String myId){
this.name = myName;
this.id = myId;
}
}
notice all the x,y,z Pos variables yRot and direction are all strings, Ideally I'd like them to be floats. You may by now know why this is. All players are stored in a hashmap as they come into the world.
When a player comes into the world the actionscript calls a function on the server ....
public synchronized void sendClientDetails(Object[] params) {
// send all client details
log.info("Sending client details to:-" + params[0].toString() + "Id:-"
+ params[1].toString());
IScope appScope = Red5.getConnectionLocal().getScope();
// player[0] = params[0].toString();
// player[1] = params[1].toString();
Iterator<IConnection> it = appScope.getConnections();
IConnection excluded = null;
while (it.hasNext()) {
excluded = it.next();
if (excluded.getClient().getId().equals(params[1].toString())) {
break;
// if (conn.equals(current)) {
// continue;
// }
// if (conn instanceof IServiceCapableConnection) {
// ServiceUtils.invokeOnClient(conn.getClient(), appScope,
// "createPlayer", new Object[] {player});
// }
}
}
Iterator<IConnection> it2 = appScope.getConnections();
while (it2.hasNext()) {
IConnection conn = it2.next();
if (!conn.getClient().getId().equals(excluded.getClie nt().getId())) {
// if (conn.equals(current)) {
// continue;
// }
// if (conn instanceof IServiceCapableConnection) {
Player player = playerData.get(conn.getClient().getId());
String[] playerInfo = { player.getId(), player.getName(),
player.xPos, player.yPos, player.zPos, player.yRot };
ServiceUtils.invokeOnClient(excluded.getClient(), appScope,
"createVisitor", new Object[] { playerInfo });
// }
}
}
}
notice I have to build an array out of the player abject and send it out because it seems this is the only way to get all the data back to the client ... let me explain ... in action script the data is received in this function ...
public function createVisitor(responce:Object):void {
trace(responce.xPos);
myApp.createVisitor(responce[0], responce[1], responce[2], responce[3], responce[4], responce[5]);
}
this code as well as the building of the array on the server seems so inefficient, but it works well right now. It is passed the array built from the player object . If I pass it the actual player object the only data I can seem to get is the responce.name and responce.id ... notice the trace(responce.xPos); this always returns null aswell as all the others that should be there like responce.direction. So i guess after all this my question would be how do I convert the Object[] params in the java server to responce:Object in actionscript or is it even possible ... I know it can be done using java to java but whats up with java to actionscript and vice verse because it happens sending data from actionscript to red5 as well. I hope I didn't make the question to confusing I'm sure the is someone out there that know exactlly what I'm dealing with ... thanks for all the help in advance.
public class Player extends Object{
public String name;
public String id;
public String xPos;
public String yPos;
public String zPos;
public String yRot;
public String direction;
public Player(String myName, String myId){
this.name = myName;
this.id = myId;
}
}
notice all the x,y,z Pos variables yRot and direction are all strings, Ideally I'd like them to be floats. You may by now know why this is. All players are stored in a hashmap as they come into the world.
When a player comes into the world the actionscript calls a function on the server ....
public synchronized void sendClientDetails(Object[] params) {
// send all client details
log.info("Sending client details to:-" + params[0].toString() + "Id:-"
+ params[1].toString());
IScope appScope = Red5.getConnectionLocal().getScope();
// player[0] = params[0].toString();
// player[1] = params[1].toString();
Iterator<IConnection> it = appScope.getConnections();
IConnection excluded = null;
while (it.hasNext()) {
excluded = it.next();
if (excluded.getClient().getId().equals(params[1].toString())) {
break;
// if (conn.equals(current)) {
// continue;
// }
// if (conn instanceof IServiceCapableConnection) {
// ServiceUtils.invokeOnClient(conn.getClient(), appScope,
// "createPlayer", new Object[] {player});
// }
}
}
Iterator<IConnection> it2 = appScope.getConnections();
while (it2.hasNext()) {
IConnection conn = it2.next();
if (!conn.getClient().getId().equals(excluded.getClie nt().getId())) {
// if (conn.equals(current)) {
// continue;
// }
// if (conn instanceof IServiceCapableConnection) {
Player player = playerData.get(conn.getClient().getId());
String[] playerInfo = { player.getId(), player.getName(),
player.xPos, player.yPos, player.zPos, player.yRot };
ServiceUtils.invokeOnClient(excluded.getClient(), appScope,
"createVisitor", new Object[] { playerInfo });
// }
}
}
}
notice I have to build an array out of the player abject and send it out because it seems this is the only way to get all the data back to the client ... let me explain ... in action script the data is received in this function ...
public function createVisitor(responce:Object):void {
trace(responce.xPos);
myApp.createVisitor(responce[0], responce[1], responce[2], responce[3], responce[4], responce[5]);
}
this code as well as the building of the array on the server seems so inefficient, but it works well right now. It is passed the array built from the player object . If I pass it the actual player object the only data I can seem to get is the responce.name and responce.id ... notice the trace(responce.xPos); this always returns null aswell as all the others that should be there like responce.direction. So i guess after all this my question would be how do I convert the Object[] params in the java server to responce:Object in actionscript or is it even possible ... I know it can be done using java to java but whats up with java to actionscript and vice verse because it happens sending data from actionscript to red5 as well. I hope I didn't make the question to confusing I'm sure the is someone out there that know exactlly what I'm dealing with ... thanks for all the help in advance.