join the prijm community

prijm is a community of people, just like you helping each other.
join them, it only takes a minute :)

Socket.io not connecting through localhost

Hi, I was watching this video: (18) Real Time Python Chat Application using Python Flask SocketIO - YouTube

When I reach the point to check if my ChatAppPage.html is showing "user connected" in the console but instead it keeps giving me this error: Failed to load http://localhost/socket.io/?EIO=3&transport=polling&t=L_Nbg2Y: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'null' is therefore not allowed access. The response had HTTP status code 404.


My code for chatapp.py:

from flask import Flask, render_template

from flask_socketio import SocketIO, emit


app = Flask(__name__)


app.config[ 'SECRET_KEY' ] = 'Abbas'


socketio = SocketIO( app )


@app.route( '/' )

def index():

    return render_template( './ChatAppPage.html' )


@socketio.on( 'An Event' )

def handle_my_custom_event( json ):

socketio.emit( 'my response', json )


if __name__ == '__main__':

    socketio.run( app, debug = True )

my code from ChatAppPage.html:

<!-- jQuery (necessary for Bootstrap's JavaScript plugins) -->

    [removed][removed]

    [removed][removed]

    [removed][removed]

    

    [removed]

    // broadcast a message

    socket.emit( 'An Event', {

    })

    var form = $( 'form' ).on( 'submit', function( e ) {

    var user_name = $( 'input.username' ).val()

    console.log( user_name, message )

    // capture message

    console.log( msg )

    } ) 

    [removed]


  </body></p>

</html></p>I have tried to add in different ports like 8000 and 3001 and 5000 but nothing seems to be working, its not being able to connect to socket.io at all. Please help!



0 0
please login or signup to reply
post a reply
discussion resolution do more with this discussion
followed by 1 user added by 0 user save this discussion to reply later make this discussion anonymous
discussion stats
views: 235
replies: 0
favorites: 0
follower: 1
saved: 0
comments: 0