Flask-SocketIO | Socket.IO integration for Flask applications | Socket library

 by   miguelgrinberg Python Version: v5.3.4 License: MIT

kandi X-RAY | Flask-SocketIO Summary

kandi X-RAY | Flask-SocketIO Summary

Flask-SocketIO is a Python library typically used in Networking, Socket applications. Flask-SocketIO has no bugs, it has no vulnerabilities, it has build file available, it has a Permissive License and it has medium support. You can install using 'pip install Flask-SocketIO' or download it from GitHub, PyPI.

Socket.IO integration for Flask applications.
Support
    Quality
      Security
        License
          Reuse

            kandi-support Support

              Flask-SocketIO has a medium active ecosystem.
              It has 5038 star(s) with 896 fork(s). There are 109 watchers for this library.
              OutlinedDot
              It had no major release in the last 6 months.
              There are 8 open issues and 1546 have been closed. On average issues are closed in 102 days. There are no pull requests.
              It has a neutral sentiment in the developer community.
              The latest version of Flask-SocketIO is v5.3.4

            kandi-Quality Quality

              Flask-SocketIO has 0 bugs and 0 code smells.

            kandi-Security Security

              Flask-SocketIO has no vulnerabilities reported, and its dependent libraries have no vulnerabilities reported.
              Flask-SocketIO code analysis shows 0 unresolved vulnerabilities.
              There are 6 security hotspots that need review.

            kandi-License License

              Flask-SocketIO is licensed under the MIT License. This license is Permissive.
              Permissive licenses have the least restrictions, and you can use them in most projects.

            kandi-Reuse Reuse

              Flask-SocketIO releases are not available. You will need to build from source code and install.
              Deployable package is available in PyPI.
              Build file is available. You can build the component from source.
              Installation instructions, examples and code snippets are available.
              It has 1636 lines of code, 160 functions and 12 files.
              It has high code complexity. Code complexity directly impacts maintainability of the code.

            Top functions reviewed by kandi - BETA

            kandi has reviewed Flask-SocketIO and discovered the below as its top functions. This is intended to give you an instant insight into Flask-SocketIO implemented functionality, and help decide if they suit your requirements.
            • Send data to the client
            • Emit an event
            • Handle an event
            • Register a handler for an event
            • Decorator to register an event handler
            • Disconnects the current request
            • Disconnect from the server
            • A background thread
            • Sleep the server
            • Called when a connection is closed
            • Close a room
            • My_room event handler
            • Called when a message is received
            • Run Flask application
            • Message received from my room
            • Handle a disconnect request
            • Broadcast an event
            • Message received from server
            • Connects to the thread
            • Get the current session
            • Called when a room is closed
            • Called when a room is joined
            • Called when the client is connected
            • Register a namespace handler
            • Trigger an event
            • Decorator to register a handler
            Get all kandi verified functions for this library.

            Flask-SocketIO Key Features

            No Key Features are available at this moment for Flask-SocketIO.

            Flask-SocketIO Examples and Code Snippets

            Flask-SocketIO - app
            Pythondot img1Lines of Code : 83dot img1License : Permissive (MIT License)
            copy iconCopy
            from threading import Lock
            from flask import Flask, render_template, session, request, \
                copy_current_request_context
            from flask_socketio import SocketIO, emit, join_room, leave_room, \
                close_room, rooms, disconnect
            
            # Set this variable to "t  
            Flask-SocketIO - app namespace
            Pythondot img2Lines of Code : 72dot img2License : Permissive (MIT License)
            copy iconCopy
            from threading import Lock
            from flask import Flask, render_template, session, request
            from flask_socketio import SocketIO, Namespace, emit, join_room, leave_room, \
                close_room, rooms, disconnect
            
            # Set this variable to "threading", "eventlet" or   
            Flask-SocketIO - sessions
            Pythondot img3Lines of Code : 55dot img3License : Permissive (MIT License)
            copy iconCopy
            from flask import Flask, render_template, session, request, jsonify
            from flask_login import LoginManager, UserMixin, current_user, login_user, \
                logout_user
            from flask_session import Session
            from flask_socketio import SocketIO, emit
            
            app = Flask(  

            Community Discussions

            QUESTION

            How can I emit Flask-SocketIO requests with callbacks that still work after a user rejoins and their sid changes?
            Asked 2022-Apr-02 at 15:19
            Summarize the Problem

            I am using Flask-SocketIO for a project and am basically trying to make it so that users can rejoin a room and "pick up where they left off." To be more specific:

            1. The server emits a request to the client, with a callback to process the response and a timeout of 1 second. This is done in a loop so that the request is resent if a user rejoins the room.
            2. A user "rejoining" a room is defined as a user joining a room with the same name as a user who has previously been disconnected from that room. The user is given their new SID in this case and the request to the client is sent to the new SID.

            What I am seeing is this:

            1. If the user joins the room and does everything normally, the callback is processed correctly on the server.

            2. It a user rejoins the room while the server is sending requests and then submits a response, everything on the JavaScript side works fine, the server receives an ack but does not actually run the callback that it is supposed to:

              ...

            ANSWER

            Answered 2022-Apr-02 at 15:19

            The reason why those callbacks do not work is that you are making the emits from a context that is based on the old and disconnected socket.

            The callback is associated with the socket identified by request.sid. Associating the callback with a socket allows Flask-SocketIO to install the correct app and request contexts when the callback is invoked.

            The way that you coded your color prompt is not great, because you have a long running event handler that continues to run after the client goes aways and reconnects on a different socket. A better design would be for the client to send the selected color in its own event instead of as a callback response to the server.

            Source https://stackoverflow.com/questions/71700501

            QUESTION

            Pip Package dependency overriding specified version in requirements.txt
            Asked 2022-Mar-22 at 16:17

            I got a Flask App and installed the dependencies out of the requirements.txt. I got the following error when running my App:

            ...

            ANSWER

            Answered 2022-Mar-22 at 16:17

            Use pipenv: https://pipenv.pypa.io/.

            At least some time ago, Pip used to have some flaws in solving multiple packages dependencies. I now saw an update note on their documentation that seems to tackle the problem; haven't tested yet. Pipenv would solve the dependencies graph just fine. That was one of the reason I started using Pipenv.

            Please, have a look at the following pages:

            Source https://stackoverflow.com/questions/71575177

            QUESTION

            Socket connection is closed every minute
            Asked 2022-Mar-09 at 19:00

            I'm configuring a Flask-SocketIO server.

            When locally connecting a socket (http://127.0.0.1:5000), it's normally working. But after deploying it into my GCP virtual machine, sockets connected over https are closed and reconnected every minute as shown below (looks like socket connection requests are timed out at this interval).

            I've already tried with all async modes, including eventlet, gevent, and threading as well as gunicorn and uwsgi. Some configurations allow a 2-min timeout but no approach resolves the issue fundamentally.

            How can I solve this?

            ...

            ANSWER

            Answered 2022-Mar-09 at 19:00

            Read this topic its because of the Google loadbalancer

            Br

            Source https://stackoverflow.com/questions/71412181

            QUESTION

            Trouble using pyinstaller "No module named '_ssl'"
            Asked 2022-Mar-04 at 09:40

            I trying to use pyinstaller to generate my binary file in python. In my program I use flask_socketio. I try to generate my binary file with that command:

            ...

            ANSWER

            Answered 2022-Mar-04 at 09:40

            I finally find the solution. For people who facing the same trouble:

            Here is the command I use for create the binary file:

            Source https://stackoverflow.com/questions/71319603

            QUESTION

            Flask SocketIO message ack not received
            Asked 2022-Jan-16 at 16:55

            Flask 2.0.2
            Flask-SocketIO 5.1.1

            I am trying to build a very simple Flask SocketIO server which sends a message to the client when he connects to the server, and receives the acknowledgement of that message. I am testing my server with this SocketIO client tool. Sending the message upon connection is working, however my server does not receive the ack of the client. These are my connection and ack method:

            ...

            ANSWER

            Answered 2021-Nov-08 at 13:16

            Apparently this client I used did not implement calling the callback function. Implementing a client myself that calls the callback function upon receiving a message solved the issue.

            Source https://stackoverflow.com/questions/69883040

            QUESTION

            Flask-SocketIO access session from background task
            Asked 2022-Jan-14 at 13:14

            I have a Flask app for http and web socket (Flask-SocketIO) communication between client and server using gevent. I also use server side session with Flask-Session extension for the app. I run a background task using SocketIO.start_background_task. And from this task, I need to access session information which will be used to emit message using socketio. I get error when accessing session from the task "RuntimeError: Working outside of request context." This typically means that you attempted to use functionality that needed an active HTTP request.

            Socket IO instance is created as below- socket_io = SocketIO(app, async_mode='gevent', manage_session=False)

            Is there any issue with this usage. How this issue could be addressed?

            Thanks

            ...

            ANSWER

            Answered 2022-Jan-14 at 13:14

            This is not related to Flask-SocketIO, but to Flask. The background task that you started does not have request and application contexts, so it does not have access to the session (it doesn't even know who the client is).

            Flask provides the copy_current_request_context decorator duplicate the request/app contexts from the request handler into a background task.

            The example from the Flask documentation uses gevent.spawn() to start the task, but this would be the same for a task started with start_background_task().

            Source https://stackoverflow.com/questions/70700914

            QUESTION

            Flask SocketIO web app refuses to accept connections from python file
            Asked 2021-Dec-25 at 19:24

            I am trying to send some data to a Flask app using web sockets. Never done something like this so I might be doing something very wrong but so far I haven't been able to accept a single connection.

            For the moment I have 2 python files, server.py and client.py.

            server.py starts the flask server and the web socket, then client.py should be able to connect to it, send a message, which is printed out to the server console, then the server should echo that message back where it will be received by the client and print to the client console.

            However right now I am getting a Handshake status 400 BAD REQUEST error when the client tries to connect.

            Here is the code I'm using:

            server.py :

            ...

            ANSWER

            Answered 2021-Dec-25 at 19:24

            The problem is with your client. Websocket and socket.io aren't the same, socket.io protocol can use websockets under the hood but you cannot just connect with websocket client to socket.io server.

            What you want to use is socket.io client.

            And if you don't mind I highly encuorage you to use FastAPI instead of flask. It's much simpler, faster and have much better documentation. Here you can find complete and working example of websocket server and client with FastAPI

            Source https://stackoverflow.com/questions/70481021

            QUESTION

            Error testing flask-socketio server emitted events with pytest
            Asked 2021-Dec-19 at 19:36

            I'm building the test suite for a recently deployed webapp. It was built using flask-socketio and uses pytest for the testing suite.

            The big issue here is the lack of documentation for tests with flask-socketio. I found some projects that include a testing suite: https://github.com/miguelgrinberg/Flask-SocketIO/blob/main/test_socketio.py https://github.com/miguelgrinberg/flack/blob/master/tests/tests.py

            But none of those implement tests on server responses to messages.

            In my case, I have the following listener in my server:

            ...

            ANSWER

            Answered 2021-Dec-19 at 19:36

            The Flask-SocketIO test client is not a real client, you cannot register event handlers. The test client records anything the server emits, and allows your test to check it. Flask-SocketIO's own unit tests do this here, for example.

            Source https://stackoverflow.com/questions/70384048

            QUESTION

            SocketIO(app) missing required positional argument 'mode'
            Asked 2021-Nov-08 at 06:27

            I'm trying to get the simple example of Flask-SocketIO working, but I'm getting an error saying I'm missing a required positional argument 'mode', even though the documentation / official example don't show such a parameter:

            ...

            ANSWER

            Answered 2021-Nov-07 at 07:49

            After a lot of head-scratching, I realized it was happening because I accidentally imported the wrong SocketIO with my IDE: I imported socket.SocketIO instead of flask_socketio.SocketIO. When I fixed the import statement the error went away.

            Source https://stackoverflow.com/questions/69870622

            QUESTION

            Flask Socket-IO Server Client Not Communicating (with tweepy and twilio)
            Asked 2021-Oct-29 at 12:31

            I am trying to have a Flask Server that allows me to launch a tweepy stream and on every message received in the stream listener, it sends that message to a socketio client. The Flask server is at the same time supposed to allow Twilio to post to it, and route that message to the client—so that the client is receiving messages from both Twilio and twitter.

            I have been trying to get the server to send messages over to the client for the data incoming from twitter, the code for Twilio works just fine. It sends data over to the client on message receipt. The main loop in tweepy is also not locking up the program—I can test print statements and see tweets and the incoming sms's being printed in the handle_message(msg) function asynchronously. I feel like there must be something really simple that I am missing here since the SMS's are emitted to the client, but the incoming tweets are not, even though they are propagating through to the handle_message(msg) function. What gives?

            server.py

            ...

            ANSWER

            Answered 2021-Oct-28 at 23:25

            Twilio developer evangelist here.

            You've decorated the handle_message function as @sio.event but as far as I can see in the docs, you should only do that to have the handle_message method respond to events on the socket called "handle_message".

            I'd start be removing the @sio.event decorator.

            I'm not a Python expert, but I also wonder whether there is a scope issue here. You define your MyListener class and create an instance of it before you define the handle_message method. Just to test, can you try emitting to the socket directly within the on_data method:

            Source https://stackoverflow.com/questions/69752782

            Community Discussions, Code Snippets contain sources that include Stack Exchange Network

            Vulnerabilities

            No vulnerabilities reported

            Install Flask-SocketIO

            You can install this package as usual with pip:.

            Support

            For any new features, suggestions and bugs create an issue on GitHub. If you have any questions check and ask questions on community page Stack Overflow .
            Find more information at:

            Find, review, and download reusable Libraries, Code Snippets, Cloud APIs from over 650 million Knowledge Items

            Find more libraries
            CLONE
          • HTTPS

            https://github.com/miguelgrinberg/Flask-SocketIO.git

          • CLI

            gh repo clone miguelgrinberg/Flask-SocketIO

          • sshUrl

            git@github.com:miguelgrinberg/Flask-SocketIO.git

          • Stay Updated

            Subscribe to our newsletter for trending solutions and developer bootcamps

            Agree to Sign up and Terms & Conditions

            Share this Page

            share link

            Explore Related Topics

            Consider Popular Socket Libraries

            monolog

            by Seldaek

            libuv

            by libuv

            log.io

            by NarrativeScience

            Flask-SocketIO

            by miguelgrinberg

            Try Top Libraries by miguelgrinberg

            flasky

            by miguelgrinbergPython

            microblog

            by miguelgrinbergPython

            python-socketio

            by miguelgrinbergPython

            Flask-Migrate

            by miguelgrinbergPython

            flask-video-streaming

            by miguelgrinbergPython