无法识别的框架操作码:7 [英] Unrecognized frame opcode: 7

查看:178
本文介绍了无法识别的框架操作码:7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我用带有websockets的javascript创建了一个客户端,该客户端连接到c Sharp服务器.问题是握手后,我的连接关闭了,我不知道为什么.我得到的唯一错误是:无法识别的帧操作码:7".我使用的是Google Chrome浏览器16.0.912.75.

循序渐进:
-WebSocket可用
-服务器收到握手请求
-生成了Sec-WebSocket-Accept并将其发送到浏览器
-浏览器识别该键并执行 .onopen 方法
-在此之后我得到了错误

在我的服务器上,我有这个:

I created a client in javascript with websockets that connects to a c sharp server. The problem is that after the handshake my connection closes and I don''t know why. The only error I get is: "Unrecognized frame opcode: 7". I use Google Chrome 16.0.912.75.

Step by step:
- WebSocket available
- server receives the handshake request
- Sec-WebSocket-Accept is generated and sent to the browser
- the browser recognizes the key and the .onopen method is executed
- after this I get the error

In my server I have this:

connection.Send(Encoding.ASCII.GetBytes("HTTP/1.1 101 Switching Protocols\r\nUpgrade: WebSocket\r\nConnection: Upgrade\r\nSec-WebSocket-Accept: " + aux));
connection.Send(Encoding.ASCII.GetBytes("\r\n\r\n"));


... aux是通过此函数生成的:


... where aux is generated by this function:

public static String ComputeWebSocketHandshakeSecurityHash09(String secWebSocketKey)
        {
            const String MagicKEY = "258EAFA5-E914-47DA-95CA-C5AB0DC85B11";
            String secWebSocketAccept = String.Empty;

            // 1. Combine the request Sec-WebSocket-Key with magic key.
            String ret = secWebSocketKey + MagicKEY;

            Console.WriteLine("-   " + ret + "   -");

            // 2. Compute the SHA1 hash
            SHA1 sha = new SHA1CryptoServiceProvider();
            byte[] sha1Hash = sha.ComputeHash(Encoding.UTF8.GetBytes(ret));

            // 3. Base64 encode the hash
            secWebSocketAccept = Convert.ToBase64String(sha1Hash);

            return secWebSocketAccept;
        }



客户端看起来像这样:



The client side looks like this:

var ws;
$(document).ready(function () {

    // test if the browser supports web sockets
    if ("WebSocket" in window) {
        debug("Browser supports web sockets!", 'success');
        connect($('#host').val());
        $('#console_send').removeAttr('disabled');
    } else {
        debug("Browser does not support web sockets", 'error');
    };

    // function to send data on the web socket
    function ws_send(str) {
        try {
            ws.send(str);
        } catch (err) {
            debug(err, 'error');
        }
    }

    // connect to the specified host
    function connect(host) {

        debug("Connecting to " + host + " ...");
        try {
            ws = new WebSocket(host); // create the web socket
        } catch (err) {
            debug(err, 'error');
        }
        $('#host_connect').attr('disabled', true); // disable the 'reconnect' button

        ws.onopen = function () {
            debug("connected... ", 'success'); // we are in! :D
        };

        ws.onmessage = function (evt) {
            debug(evt.data, 'response'); // we got some data - show it omg!!
        };

        ws.onclose = function () {
            debug("Socket closed!", 'error'); // the socket was closed (this could be an error or simply that there is no server)
            $('#host_connect').attr('disabled', false); // re-enable the 'reconnect button
        };
    };

    // function to display stuff, the second parameter is the class of the <p> (used for styling)
    function debug(msg, type) {
        $("#console").append('<p class="' + (type || '') + '">' + msg + '</p>');
    };

    // the user clicked to 'reconnect' button
    $('#host_connect').click(function () {
        debug("\n");
        connect($('#host').val());
    });

    // the user clicked the send button
    $('#console_send').click(function () {
        ws_send($('#console_input').val());
    });

    $('#console_input').keyup(function (e) {
        if(e.keyCode == 13) // enter is pressed
            ws_send($('#console_input').val());
    });

});



如果您需要更多信息,请回复.我现在在此操作码上搜索google,搜索4h之类的东西:7问题.

谢谢您的帮助.



If you need more information please reply. I am searching google for like 4h now on this opcode: 7 issue.

Thank you for your help.

推荐答案

(文档).ready(// 测试浏览器是否支持Web套接字 如果(" 窗口){ debug(" ' 成功'); connect(
(document).ready(function () { // test if the browser supports web sockets if ("WebSocket" in window) { debug("Browser supports web sockets!", 'success'); connect(


(' #host').val( ));
('#host').val());


(' #console_send').removeAttr (' 已禁用'); } 其他 { debug(" ' 错误'); }; // 用于在网络套接字上发送数据的功能 功能 ws_send(str){ 尝试 { ws.send(str); } 捕获(错误){ debug(err,' 错误'); } } // 连接到指定的主机 功能 connect(host){ debug(" +主机+ " span> ..."); 尝试 { ws = WebSocket(主机); // 创建Web套接字 } 捕获(错误){ debug(err,' 错误'); }
('#console_send').removeAttr('disabled'); } else { debug("Browser does not support web sockets", 'error'); }; // function to send data on the web socket function ws_send(str) { try { ws.send(str); } catch (err) { debug(err, 'error'); } } // connect to the specified host function connect(host) { debug("Connecting to " + host + " ..."); try { ws = new WebSocket(host); // create the web socket } catch (err) { debug(err, 'error'); }


这篇关于无法识别的框架操作码:7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆