View Full Version : [AS3] RemoteObject with Java?
travikk
02-09-2008, 09:42 AM
Hello :)
I have to write a server+client application.
Server is in Java, and offers me RemoteObject calls.
As a client I have Flash. Let say, on the client side i have 100 different operations. Stupid thing would be recognizing them (on the server side) by String, and having huge switch-case block, wouldn't it? So, I thought maybe RemoteObject would solve the case.
Is there any way to do it?
Thanks is advance for the answer.
abeall
02-09-2008, 10:29 PM
I don't know anything about Java or RemoteObject, but perhaps Flash's Socket class will help.
you could also look into AMFPHP, which will let you call PHP functions from Flash, as well as pass native data formats between the two via the AMF format.
sgartner
02-10-2008, 09:18 AM
Hello :)
I have to write a server+client application.
Server is in Java, and offers me RemoteObject calls.
As a client I have Flash. Let say, on the client side i have 100 different operations. Stupid thing would be recognizing them (on the server side) by String, and having huge switch-case block, wouldn't it? So, I thought maybe RemoteObject would solve the case.
Is there any way to do it?
Thanks is advance for the answer.
Travikk,
First, I think maybe you should be asking this question in a Java Forum, since the client-side is not the one defining these 100 operations, the server-side is defining them.
No a huge switch is not the only choice. You will have to define your 100 different operations on your server in some way, reality is reality, but how you handle that is your choice. One common solution is an array of function pointers but unfortunately Java doesn't support function pointers, so you have to implement it through delegate objects, for example:
// This is the class that really knows how to handle the operations
public class OperationImplementer
{
protected void handleKillOperation (node theDataNode)
{
System.out.println("Operation: kill");
... implementation here ...
}
protected void handlePaintOperation (node theDataNode)
{
System.out.println("Operation: Paint");
... implementation here ...
}
// 98 more here
}
// First define an interface for handler listeners
public abstract class OperationHandler
{
protected operationImplementer _impl;
public operationHandler (operationImplementer impl)
{
_impl = impl;
}
public abstract void doOperation (Node theDataNode);
}
Then you define classes that handle the different operations:
class HandleKillOperation implements OperationHandler
{
public void doOperation (Node theDataNode)
{
_impl.handleKillOperation(theDataNode);
}
}
class HandlePaintOperation implements OperationHandler
{
public void doOperation (Node theDataNode)
{
_impl.handlePaintOperation(theDataNode);
}
}
// define 98 more of these using
Now create instances of the handler classes and register them in a hashtable:
OperationImplementer impl = new OperationImplementer();
Hashtable operations = new Hashtable();
operations.put("kill", new handleKillOperation(impl));
operations.put("paint", new handlePaintOperation(impl));
operations.put("other", ...);
And, finally, to execute an operation:
// Client just called with an operation...
Node operationNode = parseIncomingXML(); // Get the operation XML node
String operationName = getOperationName(operationNode); // Whatever this requires
OperationHandler handler = (OperationHandler)operations.get(operationName);
if (null != handler)
handler.doOperation(operationNode);
else
// Handle the error of an unknown operation.
Now, I obviously punted on the XML part as I assume you already know Java and any implementation I tried to do here would never match what you need to do given my lack of knowledge of your solution. If you need help with how to handle XML in Java (or if you decide to use something other than XML to communicate between your Flash and the server) then you should find a Java forum. There's lots of java-based XML tutorials on the Internet, of course, as well as lots of flash calling server using XML tutorials (though in most of these the server-side is PHP so you'll have to translate).
travikk
02-10-2008, 01:27 PM
Well, that seems to be a nice choice!
First, I think maybe you should be asking this question in a Java Forum, since the client-side is not the one defining these 100 operations, the server-side is defining them.
Yes, but client-side decides which action to execute. Server-side receives client request, does specific operation and returns result to the client. I realize, i will have to define that 100 operations, but the problem is which one to execute, right?
Your way to do this seems to be right. But in the mean-time i've found something which is called openAMF, which is java connector with flash, just like AMFPHP is. Do you have any experience with it?
Thanks for your help!
hangalot
02-10-2008, 02:24 PM
openAMF is a dead project. use Red5. its really easy to get started with tons of docs and samples
travikk
02-12-2008, 07:42 AM
Hmm, it really looks great, but I have few questions tho...
I've found a video-tutorials, and they are really grea, but they shows, that everytime i got connected to the server, I'm getting same instance of the requested class. It is wrong, how am I supposed to get new instance for each user, or each time user connects?
Also, i'd like to know what's the difference, when my class extends ApplicationAdapter, or implements Serializable? I know, in second option, i need to got interface on the client and server side, but is it the only difference? Which one works faster/better for advanced applications?
Is that all flash-java communication is an good option, as far as getting information and doing some maths on the server concerned?
hangalot
02-12-2008, 09:03 AM
Hmm, it really looks great, but I have few questions tho...
I've found a video-tutorials, and they are really grea, but they shows, that everytime i got connected to the server, I'm getting same instance of the requested class. It is wrong, how am I supposed to get new instance for each user, or each time user connects?
look at what they call remoting, thats what you are after
Also, i'd like to know what's the difference, when my class extends ApplicationAdapter, or implements Serializable? I know, in second option, i need to got interface on the client and server side, but is it the only difference? Which one works faster/better for advanced applications?
serializable means it can get pushed down the wire, you use that for value objects. for invoking remote objects you don't need to extend application adaptor (which is a session based class)
Is that all flash-java communication is an good option, as far as getting information and doing some maths on the server concerned?
yes
travikk
02-12-2008, 04:01 PM
Thanks, that really helped me.
One another question... Am I able to send some information from server without doing an action on the client-side? Something like a listener or I don't know...? But with Red5.
hangalot
02-12-2008, 04:03 PM
remote shared object
travikk
02-16-2008, 04:00 PM
Hmm...
I've got server-side done, but i have problem with client-side.
On red5 tutorials i have one which shows how to create RemoteObject on client-side but with flex, and i want to do it with flash.
Could you help ?
Same thing with Remote Shared Object...
hangalot
02-17-2008, 10:04 AM
there are flash exaplmes using as2 as well, but as3 is as3 so...
travikk
02-17-2008, 11:55 AM
You mean?
hangalot
02-17-2008, 11:59 AM
i mean either take the flex examples and transalte them into flash or take the flash as2 examples and as3 them.
travikk
02-17-2008, 12:31 PM
Can you post 1 as2 example? I coudln't find it...
hangalot
02-17-2008, 12:34 PM
its part of the samples package of red5
travikk
02-17-2008, 08:22 PM
No doubt, but cannot find any?
|
vBulletin® v3.8.4, Copyright ©2000-2009, Jelsoft Enterprises Ltd.