miguelgrinberg / flask-sock

Modern WebSocket support for Flask.
MIT License
274 stars 24 forks source link

Works with wscat not with browser or with other websocket testing tools #1

Closed naveenbharadwaj19 closed 3 years ago

naveenbharadwaj19 commented 3 years ago

This package is so easy and good . But i'm facing a problem i could not use the websocket url other than wscat. With wscat command it works fine

code :

from flask import Flask,request,jsonify,Response
from pymongo import MongoClient
import  json
from flask_sock import  Sock

app = Flask(__name__)
sock = Sock(app)

@sock.route('/test')
def echo(ws):
    while True:
        data = ws.receive()
        ws.send(data)

if __name__ == "__main__":
    app.run(port=8080,debug=True,host= "hostname")

Steps tried:

ws://<hostname>:8080/test
wss://<hostname>:8080/test

server output log : <hostname> - - [08/May/2021 19:26:54] "▬♥☺☻ ☺ ☺ü♥♥↔¯ï°nså▲æLQ"ærqçÜþ♫ÜäUÌ☺Чr^ ­◄" HTTPStatus.BAD_REQUEST -

miguelgrinberg commented 3 years ago

There is an example application in this repository that includes a web browser client. Have you tested that?

Also, you are asking about production, yet you are using Flask's development web server, which is a terrible choice to use in production. Use Gunicorn instead.

naveenbharadwaj19 commented 3 years ago

Why terrible ? host = 127.0.0.1,localhost working if i change host to my ip4 address it's not connecting you have idea why ?

miguelgrinberg commented 3 years ago

https://flask.palletsprojects.com/en/1.1.x/tutorial/deploy/#run-with-a-production-server

I'm going to stop responding to your messages until you provide the information I'm requesting. I'm not a magician, if I say that I need you to provide some details (i.e. logs) to help me understand your issue, asking the same question over and over while ignoring the request is not going to give you a solution.

naveenbharadwaj19 commented 3 years ago

Ok. Sry i'm new to websockets . I deployed the app on heroku exactly around 30 secs my websocket connection is getting disconnected this happens everytime

heroku log:

2021-05-09T10:37:06.216006+00:00 heroku[router]: at=info method=GET path="/test2" host=test-mongodb-server.herokuapp.com request_id=74d6b9df-77a0-45b3-aaeb-03bd27b2ee2a fwd="49.207.131.81" dyno=web.1 connect=3ms service=11427ms status=101 bytes=121 protocol=https
2021-05-09T10:37:10.469105+00:00 heroku[router]: at=info method=GET path="/test2" host=test-mongodb-server.herokuapp.com request_id=2a0efca8-fd8d-45ad-b36a-8b2bb834c84a fwd="49.207.131.81" dyno=web.1 connect=0ms service=3664ms status=101 bytes=114 protocol=https
2021-05-09T10:37:25.078342+00:00 app[web.1]: [2021-05-09 10:37:25 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:7)
2021-05-09T10:37:25.079112+00:00 app[web.1]: [2021-05-09 10:37:25 +0000] [7] [INFO] Worker exiting (pid: 7)
2021-05-09T10:37:25.553694+00:00 app[web.1]: [2021-05-09 10:37:25 +0000] [25] [INFO] Booting worker with pid: 25
2021-05-09T10:37:37.624566+00:00 app[web.1]: [2021-05-09 10:37:37 +0000] [4] [CRITICAL] WORKER TIMEOUT (pid:8)
2021-05-09T10:37:37.625179+00:00 app[web.1]: [2021-05-09 10:37:37 +0000] [8] [INFO] Worker exiting (pid: 8)
2021-05-09T10:37:38.110582+00:00 app[web.1]: [2021-05-09 10:37:38 +0000] [33] [INFO] Booting worker with pid: 33

websocket link: wss://test-mongodb-server.herokuapp.com/test2

miguelgrinberg commented 3 years ago

I suggest you read the documentation of the platforms that you are using. https://devcenter.heroku.com/articles/websockets#timeouts