Binary socket and policy file in Flex

Posted by Daniil on Stack Overflow See other posts from Stack Overflow or by Daniil
Published on 2010-05-17T16:16:37Z Indexed on 2010/05/17 16:20 UTC
Read the original article Hit count: 413

Filed under:
|
|
|

Hi, I'm trying to evaluate whether Flex can access binary sockets. Seems that there's a class calles Socket (flex.net package). The requirement is that Flex will connect to a server serving binary data. It will then subscribe to data and receive the feed which it will interpret and display as a chart. I've never worked with Flex, my experience lies with Java, so everything is new to me. So I'm trying to quickly set something simple up. The Java server expects the following:

DataInputStream in = .....
byte cmd = in.readByte();
int size = in.readByte();
byte[] buf = new byte[size];
in.readFully(buf);
... do some stuff and send binary data in something like
out.writeByte(1);
out.writeInt(10000);
... etc...

Flex, needs to connect to a localhost:6666 do the handshake and read data. I got something like this:

        try {
            var socket:Socket = new Socket();

            socket.connect('192.168.110.1', 9999);
            Alert.show('Connected.');
            socket.writeByte(108); // 'l'
            socket.writeByte(115); // 's'
            socket.writeByte(4);
            socket.writeMultiByte('HHHH', 'ISO-8859-1');
            socket.flush();
        } catch (err:Error) {
            Alert.show(err.message + ": " + err.toString());
        }

The first thing is that Flex does a <policy-file-request/>. I've modified the server to respond with:

<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "/xml/dtds/cross-domain-policy.dtd">

<cross-domain-policy>
   <site-control permitted-cross-domain-policies="master-only"/>
   <allow-access-from domain="192.168.110.1" to-ports="*" />
</cross-domain-policy>    

After that - EOFException happens on the server and that's it.

So the question is, am I approaching whole streaming data issue wrong when it comes to Flex? Am I sending the policy file wrong? Unfortunately, I can't seem to find a good solid example of how to do it. It seems to me that Flex can do binary Client-Server application, but I personally lack some basic knowledge when doing it.

I'm using Flex 3.5 in IntelliJ IDEA IDE.

Any help is appreciated.

Thank you!

© Stack Overflow or respective owner

Related posts about java

Related posts about flex3