theturtle32 / AS3WebSocket

ActionScript 3 WebSocket client implementation for the final WebSocket Draft RFC6455
Apache License 2.0
247 stars 97 forks source link

Connect to Autobahn with Subscribe #33

Open yozef opened 6 years ago

yozef commented 6 years ago

I would like to connect to a websocket server (Autobahn), and then subscribe to a channel.

When I use this lib:

websocket = new WebSocket("wss://api.domain.com", "*", "wsservice");

websocket.addEventListener(WebSocketEvent.CLOSED, handleWebSocketClosed);
websocket.addEventListener(WebSocketEvent.OPEN, handleWebSocketOpen);
websocket.addEventListener(WebSocketEvent.MESSAGE, handleWebSocketMessage);
websocket.addEventListener(WebSocketErrorEvent.CONNECTION_FAIL, handleConnectionFail);

websocket.connect();

--- then ---
protected function handleWebSocketOpen(event:WebSocketEvent):void {
    websocket.sendUTF(JSON.stringify({
        "type": "subscribe",
        "channels": ['channel']
    }));
}

However when I try to connect, I get the following error:

I DONT KNOW HOW TO HANDLE DER stuff of TYPE 12
Connection Failure: An HTTP response code other than 101 was received.  Actual Response Code: 400 HTTP Origin header invalid: No host part in Origin '*'
sebastiantoro commented 6 years ago

@yozef did you find a way around this?

yozef commented 6 years ago

I haven't.

sebastiantoro commented 6 years ago

I solved a very similar issue changing new WebSocket("wss://api.domain.com", "*", "wsservice") for new WebSocket("wss://api.domain.com", "", "wsservice") ("*" to "")