【问题标题】:Connecting air/flash app to websocket server将 air/flash 应用程序连接到 websocket 服务器
【发布时间】:2018-01-25 12:27:26
【问题描述】:

我正在尝试将我的空中应用程序连接到不在我的域中的 websocket 服务器。我在 GitHub 上找到了这段代码:https://github.com/theturtle32/AS3WebSocket 但我无法连接到服务器。

这是我的代码:

<fx:Script>
    <![CDATA[
        import com.worlize.websocket.WebSocket;
        import com.worlize.websocket.WebSocketErrorEvent;
        import com.worlize.websocket.WebSocketEvent;

        private var websocket:WebSocket;

        private function handleCreationComplete():void 
        {
            websocket = new WebSocket("wss://echo.websocket.org", "*");

            websocket.debug = true;

            websocket.addEventListener(WebSocketEvent.CLOSED, handleWebSocketClosed);
            websocket.addEventListener(WebSocketEvent.OPEN, handleWebSocketOpen);
            websocket.addEventListener(WebSocketEvent.MESSAGE, handleWebSocketMessage);
            websocket.addEventListener(IOErrorEvent.IO_ERROR, handleIOError);
            websocket.addEventListener(SecurityErrorEvent.SECURITY_ERROR, handleSecurityError);
            websocket.addEventListener(WebSocketErrorEvent.CONNECTION_FAIL, handleConnectionFail);

            websocket.connect();
        }

        private function handleIOError(event:IOErrorEvent):void 
        {
            trace("error");
        }

        private function handleSecurityError(event:SecurityErrorEvent):void 
        {
            trace("sec error");
        }

        private function handleConnectionFail(event:WebSocketErrorEvent):void 
        {
            trace("connection error");
        }

        private function handleWebSocketClosed(event:WebSocketEvent):void 
        {
            trace("close");
        }

        private function handleWebSocketOpen(event:WebSocketEvent):void 
        {
            trace("connected !");
        }

        private function handleWebSocketMessage(event:WebSocketEvent):void 
        {
            trace("message !");
        }


    ]]>
</fx:Script>

在端口 443 上连接到 echo.websocket.org Socket Connected 开始 SSL/TLS GET / HTTP/1.1

主机:echo.websocket.org

升级:websocket

连接:升级

Sec-WebSocket-Key:OCZu2AgYt0WgBcLFRV5EyQ==

来源:*

Sec-WebSocket-版本:13

套接字断开连接 关闭

只有我的handleWebSocketClosed 方法被触发,我的handleWebSocketOpen 从未被触发(奇怪...)。

我可以使用 pur javascript 连接服务器,所以我知道这不是服务器问题。

在 GitHub 解释项目中我可以阅读:

此客户端不适用于 draft-75 或 draft-76/-00 服务器 部署在互联网上。它仅适用于最新的 RFC6455 标准

我不知道这是否是我无法连接的原因...

这是一种使用 as3 连接到 websocket 服务器的方法吗?

感谢和抱歉我的英语不好

【问题讨论】:

    标签: actionscript-3 apache-flex websocket air


    【解决方案1】:

    看看html5 Websocket with SSL,似乎尝试通过 SSL 连接需要进行一些修改才能使用 flash.net.SecureSocket。您可能需要重写一些 AS3WebSocket 以使用它而不是 flash.net.Socket。

    【讨论】:

    • 感谢您的回复。当我在我的代码中使用 ws 而不是 wss 时,这是有效的。为什么 ?我不知道...但是当我使用我的真实网址(我可以在这里透露)进行测试时,它不起作用...HTTP Status Received: 403 Forbidden An HTTP response code other than 101 was received. Actual Response Code: 403 Forbidden 继续搜索...
    猜你喜欢
    • 2011-08-24
    • 2020-08-22
    • 1970-01-01
    • 2019-07-30
    • 1970-01-01
    • 1970-01-01
    • 2023-01-26
    • 2015-10-10
    • 2015-10-17
    相关资源
    最近更新 更多