undefinedfix
Sign in

Chrome and firebox handle websocket differently. Is it a chrome problem or a firebox problem?

golyu edited in Sat, 24 Sep 2022

Problem description

图片描述
图片描述

The background of the problem and what methods have you tried

Related codes

Front end code

    var roomName = {{ room_name_json }};

    if (window.location.protocol == 'https:') {
        var chatSocket = new WebSocket('wss://' + window.location.host + '/ws/chat/' + roomName + '/');
    } else {
        var chatSocket = new WebSocket('ws://' + window.location.host + '/ws/chat/' + roomName + '/');
    }

    chatSocket.onmessage = function (e) {
        var data = JSON.parse(e.data);
        var message = data['message'];
        document.querySelector('#chat-log').value += (message + '\n');
    };

    chatSocket.onclose = function (e) {
        console.error('Chat socket closed unexpectedly');
    };

    $('#chat-message-submit').click(function () {
        $.get(window.location.origin + "/chat/test/" + roomName, function (data) {
            console.log(data);
        });
    });

Back end code

def test(request, room_name):
    import websocket
    import time
    import ssl
    from django.conf import settings
    is_https = getattr(settings, 'IS_HTTPS', False)
    ws = websocket.WebSocket(sslopt={"cert_reqs": ssl.CERT_NONE})
    if is_https:
        ws.connect("wss://127.0.0.1/ws/chat/{}/".format(room_name))
    else:
        ws.connect("ws://127.0.0.1/ws/chat/{}/".format(room_name))

    # time.sleep(6)
    ws.send(json.dumps("Hello, World1"))
    time.sleep(6)
    ws.send(json.dumps("Hello, World2"))
    time.sleep(6)
    ws.send(json.dumps("Hello, World3"))
    time.sleep(6)
    ws.close()
    return JsonResponse(666, safe=False)

What are your expectations? What is the actual error message?

The result of firebox is right . Chrome feels like it's blocking parallel to serial . I want to know how to deal with this problem ?

0 Replies