You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hi All !
Im using Flask and Flask SocketIO to make sever . it run well when i using JS client, but when im using socketIO_client (python) to connect to sever , it cant connect to sever ! . please check this code help me ! Thanks .
my sever have ip :104.131.98.89
sever:
`
from flask import Flask, request, jsonify, render_template, session, redirect, escape
from werkzeug.utils import secure_filename
from datetime import datetime
import os
import sqlite3
from flask_socketio import SocketIO, emit
import json
import threading
DATABASE_FILE = 'database.db'
app = Flask(name, static_url_path='/static')
app.secret_key = os.urandom(12)
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app.config['UPLOAD_FOLDER'] = './static/image'
socketio = SocketIO(app, async_mode=None)
def connectdb():
conn = sqlite3.connect(DATABASE_FILE, isolation_level = None)
return conn
def querydb(conn, query, v = tuple()):
c = conn.cursor()
c.execute(query, v)
return c.fetchall()
def logged_in():
if not session.get('logged_in'):
return 0
return 1
@app.route('/')
def index():
if logged_in():
return render_template('index.html')
else:
return redirect('/dang_nhap')
@app.route('/dang_nhap', methods=['GET', 'POST'])
def dang_nhap():
if request.method == 'GET':
return render_template('dang_nhap.html')
else:
username = request.form.get('username')
password = request.form.get('password')
conn = connectdb()
r = querydb(conn, r"SELECT * FROM Administrator WHERE username=? AND password=?", (username, password))
if r:
session['logged_in'] = True
return redirect('/')
else:
return render_template('dang_nhap.html')
@app.route('/static/')
def static_file(filename):
return app.send_static_file(filename)
@app.route('/json/scan_the', methods=['POST'])
def scan_the():
json_post_data = request.get_json()
CardID = json_post_data['CardID']
DeviceID = json_post_data['DeviceID']
FingerID = json_post_data['FingerID']
ImageID = json_post_data['ImageID']
EntryTime = json_post_data['EntryTime']
conn = connectdb()
r = querydb(conn, r"SELECT * FROM Employee WHERE CardID=?", (CardID, ))
if len(r) > 0:
respone = {'status': 1}
querydb(conn, r"INSERT INTO Work(DeviceID,CardID,FingerID,ImageID,EntryTime) VALUES (?,?,?,?,?)", (DeviceID,CardID,FingerID,ImageID,EntryTime, ))
name_string = querydb(conn, r"SELECT EmployeeName FROM Employee WHERE CardID=?",(CardID,))
In client : from socketIO_client import SocketIO, LoggingNamespace import time socket = SocketIO('http://104.131.98.89',5000,LoggingNamespace) socket.emit('Ping')
it Sometimes connect , but it sometimes dont connect, it stuck in this pic and it sometimes have nothing.
The text was updated successfully, but these errors were encountered:
Hi All !
Im using Flask and Flask SocketIO to make sever . it run well when i using JS client, but when im using socketIO_client (python) to connect to sever , it cant connect to sever ! . please check this code help me ! Thanks .
my sever have ip :104.131.98.89
sever:
`
from flask import Flask, request, jsonify, render_template, session, redirect, escape
from werkzeug.utils import secure_filename
from datetime import datetime
import os
import sqlite3
from flask_socketio import SocketIO, emit
import json
import threading
DATABASE_FILE = 'database.db'
app = Flask(name, static_url_path='/static')
app.secret_key = os.urandom(12)
ALLOWED_EXTENSIONS = set(['txt', 'pdf', 'png', 'jpg', 'jpeg', 'gif'])
app.config['UPLOAD_FOLDER'] = './static/image'
socketio = SocketIO(app, async_mode=None)
def connectdb():
conn = sqlite3.connect(DATABASE_FILE, isolation_level = None)
return conn
def querydb(conn, query, v = tuple()):
c = conn.cursor()
c.execute(query, v)
return c.fetchall()
def logged_in():
if not session.get('logged_in'):
return 0
return 1
@app.route('/')
def index():
if logged_in():
return render_template('index.html')
else:
return redirect('/dang_nhap')
@app.route('/dang_nhap', methods=['GET', 'POST'])
def dang_nhap():
if request.method == 'GET':
return render_template('dang_nhap.html')
else:
username = request.form.get('username')
password = request.form.get('password')
conn = connectdb()
r = querydb(conn, r"SELECT * FROM Administrator WHERE username=? AND password=?", (username, password))
if r:
session['logged_in'] = True
return redirect('/')
else:
return render_template('dang_nhap.html')
@app.route('/static/')
def static_file(filename):
return app.send_static_file(filename)
@app.route('/json/scan_the', methods=['POST'])
def scan_the():
json_post_data = request.get_json()
CardID = json_post_data['CardID']
DeviceID = json_post_data['DeviceID']
FingerID = json_post_data['FingerID']
ImageID = json_post_data['ImageID']
EntryTime = json_post_data['EntryTime']
conn = connectdb()
r = querydb(conn, r"SELECT * FROM Employee WHERE CardID=?", (CardID, ))
if len(r) > 0:
respone = {'status': 1}
querydb(conn, r"INSERT INTO Work(DeviceID,CardID,FingerID,ImageID,EntryTime) VALUES (?,?,?,?,?)", (DeviceID,CardID,FingerID,ImageID,EntryTime, ))
name_string = querydb(conn, r"SELECT EmployeeName FROM Employee WHERE CardID=?",(CardID,))
@app.route('/Tracking', methods=['POST', 'GET'])
def tracking():
return render_template('Tracking.html')
def allowed_file(filename):
return '.' in filename and
filename.rsplit('.', 1)[1].lower() in ALLOWED_EXTENSIONS
@app.route('/rev_image', methods=['POST', 'GET'])
def upload_file():
if request.method == 'POST':
file = request.files['file']
if file and allowed_file(file.filename):
filename = secure_filename(file.filename)
file.save(os.path.join(app.config['UPLOAD_FOLDER'], filename))
post_web_data = json.dumps({"Image_status":"true"})
socketio.emit('image_response', post_web_data , namespace='/tracking')
return 'Success'
return 'Success'
@app.route('/them_nhan_vien', methods=['POST', 'GET'])
def them_nhan_vien():
if not logged_in():
return redirect('/dang_nhap')
@app.route('/json/xoa_nhan_vien', methods=['POST'])
def xoa_nhan_vien():
if not logged_in():
return redirect('/dang_nhap')
@app.route('/json/sua_thong_tin_nhan_vien', methods=['POST'])
def sua_thong_tin_nhan_vien():
if not logged_in():
return redirect('/dang_nhap')
@app.route('/them_thiet_bi', methods=['POST', 'GET'])
def them_thiet_bi():
if not logged_in():
return redirect('/dang_nhap')
@socketio.on('Ping')
def handle_ping():
print('Ping !!!')
`
In client :
from socketIO_client import SocketIO, LoggingNamespace import time socket = SocketIO('http://104.131.98.89',5000,LoggingNamespace) socket.emit('Ping')
it Sometimes connect , but it sometimes dont connect, it stuck in this pic and it sometimes have nothing.
The text was updated successfully, but these errors were encountered: