Flask Chat - Printable Version +- Python Forum (https://python-forum.io) +-- Forum: Python Coding (https://python-forum.io/forum-7.html) +--- Forum: Web Scraping & Web Development (https://python-forum.io/forum-13.html) +--- Thread: Flask Chat (/thread-11450.html) |
Flask Chat - Ahmet - Jul-09-2018 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? Flask Chat - Ahmet - Jul-09-2018 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? RE: Flask Chat - Larz60+ - Jul-09-2018 To start with, You need to show your code RE: Flask Chat - Ahmet - Jul-09-2018 https://paste.ubuntu.com/p/KCRsrWzNmD/ Here is my code. I forgot to share RE: Flask Chat - micseydel - Jul-09-2018 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). RE: Flask Chat - Ahmet - Jul-10-2018 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? RE: Flask Chat - micseydel - Jul-10-2018 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). |