Closed byrzhm closed 2 months ago
This is wrong:
sock = Sock(current_app)
The value of current_app
is undefined in the global scope, this likely gives you an error.
You need to review how Flask extensions are set up. The Flask-Sock extension must be initialized in create_app()
.
I don't know what's going on. I changed the port from 5000 (default) to 1234, and then it works! 🤨
Here are my changes:
flask run --port 1234
to start serverport='5000'
to port='1234'
in client.py
I tried another machine and used the 5000 default port, but it worked fine. 🤨
I think the reason may be that port 5000 of my original machine is occupied, but the program does not throw any exception or provide relevant information, which I find very strange. 🤨
@byrzhm You have ignored what I told you above. You cannot use current_app
in the global scope. If it works for you, then you are doing something that is non-standard. And the code above does not correctly initialize the Flask-Sock extension.
You may want to review your application and look for examples that show you the correct patterns to use, if you care at all.
Apologize ahead of time, I'm a web-dev beginner and I want to write an echo demo. But I encountered a problem.
Here is my demo project layout:
Here is
__init__.py
And here is my
serve.py
I use
flask run --debug
to run server andclient.py
to connect to the server.But the client cannot connect to the server. Here is the error message.
I think the
static
andtemplates
folders are irrelevant.