Python Forum
Thread Rating:
  • 2 Vote(s) - 3.5 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Flask Chat
#1
https://paste.ubuntu.com/p/wPwN84dwM5/

from flask import Flask, redirect, url_for, request, render_template
import settings

s=socket.socket(socket.AF_INET,socket.SOCK_DGRAM)
app = Flask(__name__)
host=socket.gethostbyname(socket.gethostname())
port=8080
s.bind((host,port)) 


def receivedata():
    while True:
        data, addr = s.recvfrom(1024)
        print(data.decode())
        print(addr)
   
   
@app.route("/", methods=['POST', 'GET'])
def home():
    if request.method == 'POST':
        return render_template('home.html')
    else:
        receivedata()
        return render_template('home.html')


app.run(debug=True)
Above the code If I call only receivedata function it works but when I try to work with flask and add flask code I take this error. I have no idea why. Error is " normally only one use is allowed for each socket address". How can I fix this error?
Reply
#2
I am trying to make a chat site with socket module. I am getting mistake when I receive data on GET method. When the program go to GET method it only wait for data even if I send data(It doesn't take data).
If I remove the receiving code from GET method and put above the Flask code there isn't any problem.How can I fix it?
Reply
#3
To start with, You need to show your code
Reply
#4
https://paste.ubuntu.com/p/KCRsrWzNmD/
Here is my code. I forgot to share
Reply
#5
Please don't create duplicate threads, or link off-site for code (as you were warned about in your first post).

You should also seriously consider providing enough code for us to reproduce your error so that we can test our proposed solutions. As it stands, I don't have a home.html file and ideally you'd provide code that doesn't require it (unless it's necessary to reproduce the problem you're asking about).
Reply
#6
I am so sorry. I didn't know the rule of this forum. So what should I do to have a answer about my problem? What should I share with you? Only home.html?
Reply
#7
Provide a Minimal, Complete, and Verifiable example - https://stackoverflow.com/help/mcve

An example of what would make it minimal would be if you can reproduce your problem without involving Flask, then you should slim down your code.
Complete means we can run it with the details you provide (without having to manually create files).
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  chat system x64 2 3,744 Mar-15-2017, 06:59 AM
Last Post: charlesprince

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020