AS3WebSocket
AS3WebSocket copied to clipboard
Connect to Autobahn with Subscribe
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 '*'
@yozef did you find a way around this?
I haven't.
I solved a very similar issue changing new WebSocket("wss://api.domain.com", "*", "wsservice") for new WebSocket("wss://api.domain.com", "", "wsservice") ("*" to "")