<

Improve company productivity with a Business Account.Sign Up

x

Flash and Socket Connections - The important bits between the lines

Published on
8,234 Points
2,234 Views
Last Modified:
Approved
The last time I worked with Flash and Socket connections was in AS1. A recent project required flash connecting to a Socket, and sending receiving information - we figured it would be easy enough - we all know about the socket policy documents and cross domain files, but after much banging head against desk, and googling, it seems this is quite a common stumbling block and I've not found anything that explicitly describes the process (from the Flash side) for someone with little or no experience doing this.

I created a basic socket class that extends the Socket - to handle the specific messages I'm using, including specific heartbearts, and progress events.

The socket is created in C#.

We got to the point where my swf file in the Flash IDE was connecting, sending and receiving as expected - however when running it in the browser it was connecting, disconnecting but never reconnecting.  Usually when I google a problem I'm having, if a lot of results are returned, I usually take that as a good sign, because if many people are having the same problem, the solution must be out there. However, in this case I didn't find it.

We followed the processes in  this Adobe Article
http://www.adobe.com/devnet/flashplayer/articles/socket_policy_files.html

In very layman terms, this is how I understand the process:

1. Flash calls socket.connect()
2. This sends a <policy-file-request/> followed by a NULL byte to the port where it is requesting a policy file.
Step 2 happens automatically - you don't need to do anything.
3. The socker server needs to respond to this policy request from flash with the policy document - which is in the form of a string. What we opted to do was have a physical document in a certain location, have the server load and read that document and return it to Flash - which would making editing / updating much easier.

Here is where we had our error.
Our own comms - we have our own "internal" end character which we're using to denote end of message.

However, we  didn't add one to this message from the server.
The Socket was returning the policy as described in the adobe article - with one exception - it didn't have a NULL byte at the end of it. \0

It might be second nature to some, it wasn't to us.
Once that was added, Flash is now able to reconnect and do what is required.
Happiness - hope this little tip helps someone.
0
Comment
Author:blue-genie
0 Comments

Featured Post

Get expert help—faster!

Need expert help—fast? Use the Help Bell for personalized assistance getting answers to your important questions.

Join & Write a Comment

In this tutorial viewers will learn how to create a basic motion tween animation in Flash Open a new document in Flash: Draw/import an image: Press CTRL + F8 to convert it into a graphic symbol: Select a frame (how long you want the tween to last): …
The goal of the tutorial is to teach the user what frame rate is, how to control it and what effect it has on the video.
Other articles by this author
Next Article:

Keep in touch with Experts Exchange

Tech news and trends delivered to your inbox every month