简体   繁体   中英

/socket.io/* 404 not found flask

I am trying to get socketio working correctly. When I load my page with following javascript. It tries to pull the socket.io page as expected but get a 404 not found each time.

<div id="result"></div>
<script src="//code.jquery.com/jquery-1.11.0.min.js"></script>
<script src="//code.jquery.com/jquery-migrate-1.2.1.min.js"></script>
<script src="https://cdn.socket.io/socket.io-1.2.1.js"></script>
<script>
$(function(){
    var socket = io.connect('/endpoint');

    // on receive append data.sound and linebreak to result id on page
    socket.on('receive', function(data){
        $('#result').append(data.mytext);
    });

    $('form#emit').submit(function(event) {
        socket.emit('submit', {account: $('#account').val(),
...

Here is the flask endpoint for the socketIO to use

@app.route('/socket.io/<path:remaining>')
def iocg(remaining):
    from websocketinstructions import WebSocketInstructions
    socketio_manage(request.environ, {'/endpoint': WebSocketInstructions}, request)
    return 'done'


127.0.0.1 - - [2014-11-24 15:29:05] "GET /socket.io/?EIO=3&transport=polling&t=1416864545405-114 HTTP/1.1" 404 342 0.002768
127.0.0.1 - - [2014-11-24 15:29:06] "GET /socket.io/?EIO=3&transport=polling&t=1416864546666-4 HTTP/1.1" 404 342 0.002745
127.0.0.1 - - [2014-11-24 15:29:10] "GET /socket.io/?EIO=3&transport=polling&t=1416864550413-115 HTTP/1.1" 404 342 0.003090
127.0.0.1 - - [2014-11-24 15:29:11] "GET /socket.io/?EIO=3&transport=polling&t=1416864551672-5 HTTP/1.1" 404 342 0.003325
127.0.0.1 - - [2014-11-24 15:29:15] "GET /socket.io/?EIO=3&transport=polling&t=1416864555419-116 HTTP/1.1" 404 342 0.003315
127.0.0.1 - - [2014-11-24 15:29:16] "GET /socket.io/?EIO=3&transport=polling&t=1416864556678-6 HTT P/1.1" 404 342 0.002707
127.0.0.1 - - [2014-11-24 15:29:20] "GET /socket.io/?EIO=3&transport=polling&t=1416864560425-117 HTTP/1.1" 404 342 0.002710
127.0.0.1 - - [2014-11-24 15:29:21] "GET /socket.io/?EIO=3&transport=polling&t=1416864561684-7 HTTP/1.1" 404 342 0.003227

First, check if the link to the CDN is valid. If doesn't work, change it to a new link from here , for example:

https://cdnjs.cloudflare.com/ajax/libs/socket.io/1.3.5/socket.io.min.js

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM