views:

22

answers:

2

I'v been looking and I can't seem to figure this out below is my code.

import flash.net.Socket;

var mySocket = new Socket

mySocket.connect("127.0.0.1", 5331)

var sym:SimpleButton;

sym.addEventListener(MouseEvent.MOUSE_DOWN, symbtn); function symbtn(event:MouseEvent):void { mySocket.writeUTFBytes(1); }

A: 
if (mySocket.connected) 
www0z0k
A: 

Flash player implements a strange (and arguably broken ?) model for security concerning sockets. It needs to receive permission from the server before it will send anything you ask it, and its way to ask for it is, as it turns out, try to connect to the port 843 on the same server to send it some arbitrary permission-asking XML string, and if that doesn't work, it will send that same XML string in the very same socket that you asked for. The server is supposed to reply in the expected way in either of the connections, or you get an error. This happens automatically before your first byte is even transmitted.

To check whether this is indeed what is happening to you, check what the server is receiving. If you see some XML data even though you didn't send any, then it's exactly that: Flash player asking for permission.

There are no ways as far as I'm aware to get Flash Player to skip asking, so you have to comply to it if it's going to work.

  • If you control your protocol but don't want to put a little program answering on port 843, you have to embed the logic Flash Player expects in your protocol. It has to be XML, it has to be the very first thing your socket sees, but once it's done you're free to send and receive whatever binary data you want.
  • If on the opposite you're trying to implement some standard protocol that you cannot change, then you must have the server answer on port 843 where Flash Player is going to knock.
  • If you can't do either of these, you're out of luck.

More information on adobe.com here. Googling for "flash player policy-file" will also help you finding a lot of information about this problem.

In the interest of sharing, here is what my personal policy file server (in Ruby) looks like. As you can see, it can be quite simple. Of course it doesn't have to be Ruby, you can implement that in whatever language you want as long as it sends the reply that Flash Player expects.

#!/usr/bin/ruby -w

require 'socket'

PORT = 843
POLICY_FILE = <<EOF
<?xml version="1.0"?>
<!DOCTYPE cross-domain-policy SYSTEM "http://www.macromedia.com/xml/dtds/cross-domain-policy.dtd"&gt;
<cross-domain-policy>
   <allow-access-from domain="put-your-domain-name-here.com" to-ports="5331" />
</cross-domain-policy>
EOF

gs = TCPServer.new(PORT)
socks = [gs]
while true
  begin
    nsock = select(socks, nil, nil, 1)
    nsock[0].each do |s|
      if s == gs
        new_sock = s.accept
        $stderr.puts "Accepted " + new_sock.to_s
        socks.push(new_sock)
      else
        if s.eof?
          $stderr.puts "Closed " + s.to_s
          s.close
          socks.delete s
        else
          $stderr.puts s
          s.write POLICY_FILE
          s.close
          socks.delete s
        end
      end
    end unless nsock.nil?
  rescue Errno::EAGAIN, Errno::ECONNABORTED, Errno::EPROTO, Errno::EINTR
    $stderr.puts "Info : exc"
    retry
  end
end
Jean