Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / January 2006

Tip: Looking for answers? Try searching our database.

Java Flash Application Communication

Thread view: 
Jessica - 27 Jan 2006 20:47 GMT
I am trying to have a web-based flash application communicate with my
Java program.

The basic architecture is a pre-existing web-based flash application
and the Java application that I have created (I can edit and change
these files).  What I need to do is have the Flash application send a
single String that it gets from web input to my Java application, and
then wait for the String that the Java application sends back after
completing its program.

Does anyone know how to do this?  I do not have access to change much
about the Flash files, but I can edit the Java files and also employ
ColdFusion or any other languages that might be required as a go
between.

Any help is greatly appreciated.
Oliver Wong - 27 Jan 2006 20:58 GMT
>I am trying to have a web-based flash application communicate with my
> Java program.
[quoted text clipped - 12 lines]
>
> Any help is greatly appreciated.

   Where does the Java application run? On the HTTP server from which the
Flash is being served? On a different server? As an application on the
client machine viewing the Flash? As an applet embedded in the same HTML
page that the flash is presented in? As an applet in a different HTML page?

   - Oliver
Jessica - 27 Jan 2006 21:10 GMT
The Java application will run on the same HTTP server as the Flash
application.

I would be able to convert the Java code to an applet (on either the
same page as the Flash or a different page), if that would solve the
communication issue, although that would not be best since the Java
code will need to eventually access a database.
Oliver Wong - 27 Jan 2006 21:24 GMT
> The Java application will run on the same HTTP server as the Flash
> application.
[quoted text clipped - 3 lines]
> communication issue, although that would not be best since the Java
> code will need to eventually access a database.

   So is the Java program running as a server listening on a specifc port
that the Flash could connect to?

   - Oliver
Jessica - 27 Jan 2006 22:56 GMT
Currently it is a stand-alone Java application, and not on the web at
all.  I wrote it, however, and could transform it into a Servlet, or
another type of web-based application if that is what is required.

I'm not sure how to connect Flash and Java on a specific port.
Oliver Wong - 27 Jan 2006 23:02 GMT
> Currently it is a stand-alone Java application, and not on the web at
> all.  I wrote it, however, and could transform it into a Servlet, or
> another type of web-based application if that is what is required.
>
> I'm not sure how to connect Flash and Java on a specific port.

   I'm not too familiar with Servlets, but my understanding is that
Servlets are run by a web server (perhaps running on port 80, for example),
and responds to HTTP requests.

   It looks like the standard way to get Flash to communicate over a socket
is to use the XMLSocket object. See
http://www.macromedia.com/support/flash/action_scripts/actionscript_dictionary/a
ctionscript_dictionary860.html


   I would convert the Java application into a server that listens on some
port (e.g. 4000), let the Flash program connect to that socket, and they
could communicate freely. In your case, you just need a String send from
Flash to Java, and then one from Java to Flash, after which you could
disconnect.

   As a first step, you should probably write a Java server that just dumps
whatever it receives in a file or to the console, and have your Flash
application connect to it, to see what protocol XMLSocket uses. Based on its
name, it sounds like it'll send an XML message, e.g something like:

<XMLSocketData>
 <StringData>Hello world!</StringData>
</XMLSocketData>

   And it probably expects a responce in XML as well. See if you can just
get your "dummy" Java server program to talk to the Flash program. Once
you've got the protocol figured out, look into converting your "real" Java
program into a server using the protocol XMLSocket expects.

   - Oliver
Daniel Dyer - 27 Jan 2006 23:12 GMT
>     It looks like the standard way to get Flash to communicate over a  
> socket
> is to use the XMLSocket object.

My current project is a Java server that communicates with Flash clients.  
If you want a continuous connection for asynchronous messaging, XML  
Sockets is probably the way to go.  Flash's support for web-services is  
also worth looking into if you just have a request/response model.  I  
don't know the details though because I am only involved on the Java side.

>     As a first step, you should probably write a Java server that just  
> dumps
[quoted text clipped - 6 lines]
>   <StringData>Hello world!</StringData>
> </XMLSocketData>

You can use pretty much any well-formed XML, it's not a particular  
Macromedia XML format that you have to use.  You just send XML documents  
down the socket, separated by a single null byte ('\u0000' in Java).

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Daniel Dyer - 27 Jan 2006 22:08 GMT
> I am trying to have a web-based flash application communicate with my
> Java program.
[quoted text clipped - 12 lines]
>
> Any help is greatly appreciated.

If you could change the Flash movie, you would have the option of using a  
web service or XML sockets.

A less invasive approach would be to have the Flash movie call a  
Javascript function and then have that do the communication with the  
server.  But if the movie doesn't already have some kind of hook for you  
to get the data you are going to have problems solving your problem  
without editing the movie.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk

Jessica - 27 Jan 2006 23:02 GMT
I will have the ability to change the movie slightly, basically add
only whatever actionscript code (I am not a flash programmer) is
required to send off the String and get the new String back.

How would I call a Javascript function from the Flash movie?  And then
I'm not sure how you call a Java application from Javascript?

I think that using Javascript might somehow be the solution, but I'm
just not sure how to implement the details.
Daniel Dyer - 27 Jan 2006 23:16 GMT
> I will have the ability to change the movie slightly, basically add
> only whatever actionscript code (I am not a flash programmer) is
[quoted text clipped - 5 lines]
> I think that using Javascript might somehow be the solution, but I'm
> just not sure how to implement the details.

I don't know how to invoke JavaScript from ActionScript, but it is  
definitely possible.  Try a Google search or a Flash newsgroup.

What kind of Java app do you have?  If you have an applet you can invoke a  
method on it from JavaScript.  It used to be done via what Netscape called  
LiveConnect.  I don't know if that's still the way to do it.

If your app is a servlet or other web-app you can probably just access it  
through an HTTP request from JavaScript.  Ask for advice on this on  
comp.lang.javascript.

Dan.

Signature

Daniel Dyer
http://www.dandyer.co.uk



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.