ActionScript + Ruby

64 Views Asked by At

I'm using WebSocket on ruby server.

require          'em-websocket'

def start_server(host, port)
  EM.run {
    EM::WebSocket.run(:host => host, :port => port) do |ws|
      ws.onopen {

      }
      ws.onmessage {
      }
      ws.onclose {

      }
    end
    puts 'Server is running at' + Time.now().to_s
  }
end

start_server('localhost', 8090)

I need to send request from ActionScript client. How I can do it? My code doesn't work.

var loader:URLLoader = new URLLoader();
        var request = new URLRequest("http://localhost:8090");
        request.method = URLRequestMethod.POST;
        var variables:URLVariables = new URLVariables();
        variables.exampleSessionId = new Date().getTime();
        variables.exampleUserLabel = "guest";
        request.data = variables;
        try {
            loader.load(request);

        } catch (error:Error) {
            trace("Unable to load requested document.");
        }

Maybe, you can suggest other implementation of ruby http server. Thank you.

1

There are 1 best solutions below

0
On

I can't speak for the Ruby side, but in AS3 the URLLoader is not meant to connect to a Web Socket, it's meant to load http resources. For Web Sockets in AS3 you must use a Socket. There is no built in implementation of the Web Socket standard in AS3, but there are 3rd party libraries such as AS3WebSocket.