Communicating with Java over a Socket via Actionscript 3
Sunday, August 5th, 2007The goal here is to get you communicating. I will provide you with an explanation of what I’m doing without exhausting what is happening. I hope to put you in a position to experiment with your own ideas, because really… that’s the best way to learn.
So the first thing we should ask ourselves is… what is really going on? I’m sure you know that you’re trying to talk to Java and you know that you want to do it using Actionscript 3, but I’m going to assume that you are reading this more because you don’t know how to communicate your own Java application back to Actionscript. Maybe you don’t know Java at all and don’t really have a reason to, but a way to communicate with your own application that can integrate multiple users in a more real time way may be a good reason, although we will not introduce multi-threading, and therefore multi-user support, until the second article. So… maybe I should should just get on with it…
If you are not familiar with Java you will probably need to get the sdk and learn how to compile a Java program. You can find that info here [insert link to tutorial on compiling java]
Basically this is what is going to be happening. Actionscript opens up a Socket to a port at some location. On that port at that location a program is listening and waiting to handle that connection. Actionscript will listen to that Socket for messages from the program as well as use that Socket to write messages back to the program. The program, which we will write in Java, will use a ServerSocket to communicate with the Socket.
With most of the crappy details removed that is what is going to happen in our system. I am going to step through how we get it running on both ends.