mirror of
https://github.com/30hours/3lips.git
synced 2024-11-18 12:33:58 +00:00
Fixed weird timeout issue
This commit is contained in:
parent
7621c04949
commit
b558ac3d4e
6 changed files with 23 additions and 12 deletions
|
@ -60,10 +60,11 @@ def serve_static(file):
|
||||||
@app.route("/api")
|
@app.route("/api")
|
||||||
def api():
|
def api():
|
||||||
api = request.query_string.decode('utf-8')
|
api = request.query_string.decode('utf-8')
|
||||||
reply = message_api_request.send_message(api)
|
try:
|
||||||
|
reply = message_api_request.send_message(api)
|
||||||
|
except Exception as e:
|
||||||
|
reply = "Exception: " + str(e)
|
||||||
print(reply, flush=True)
|
print(reply, flush=True)
|
||||||
urls = request.args.getlist("url")
|
|
||||||
data = [{"url": 'http://' + url} for url in urls]
|
|
||||||
return reply
|
return reply
|
||||||
|
|
||||||
@app.route("/map/<path:file>")
|
@app.route("/map/<path:file>")
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
function event_radar() {
|
function event_radar() {
|
||||||
|
|
||||||
radar_url = window.location.origin + '/api' + window.location.search;
|
var radar_url = window.location.origin +
|
||||||
console.log(radar_url);
|
'/api' + window.location.search;
|
||||||
|
|
||||||
fetch(radar_url)
|
fetch(radar_url)
|
||||||
.then(response => {
|
.then(response => {
|
||||||
|
@ -11,8 +11,15 @@ function event_radar() {
|
||||||
return response.json();
|
return response.json();
|
||||||
})
|
})
|
||||||
.then(data => {
|
.then(data => {
|
||||||
// Update aircraft points based on new data
|
for (const key in data["detections_localised"]) {
|
||||||
console.log("test");
|
if (data["detections_localised"].hasOwnProperty(key)) {
|
||||||
|
const target = data["detections_localised"][key];
|
||||||
|
const points = target["points"];
|
||||||
|
|
||||||
|
console.log(points);
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
})
|
})
|
||||||
.catch(error => {
|
.catch(error => {
|
||||||
// Handle errors during fetch
|
// Handle errors during fetch
|
||||||
|
|
|
@ -184,7 +184,7 @@ window.addEventListener('load', function () {
|
||||||
|
|
||||||
// add radar points
|
// add radar points
|
||||||
const radar_names = new URLSearchParams(
|
const radar_names = new URLSearchParams(
|
||||||
window.location.search).getAll('url');
|
window.location.search).getAll('server');
|
||||||
console.log(radar_names);
|
console.log(radar_names);
|
||||||
var radar_config_url = radar_names.map(
|
var radar_config_url = radar_names.map(
|
||||||
url => `http://${url}/api/config`);
|
url => `http://${url}/api/config`);
|
||||||
|
|
|
@ -45,7 +45,7 @@ document.getElementById('buttonMap').addEventListener('click', function() {
|
||||||
var adsb = document.querySelector('[name="adsb"]').value;
|
var adsb = document.querySelector('[name="adsb"]').value;
|
||||||
|
|
||||||
// Construct the URL with the form values
|
// Construct the URL with the form values
|
||||||
var apiUrl = '?url=' + Array.from(servers).map(server => server.value).join('&url=');
|
var apiUrl = '?server=' + Array.from(servers).map(server => server.value).join('&server=');
|
||||||
var mapUrl = '/map/index.html' + apiUrl + '&associator=' + associator + '&coordreg=' + coordreg + '&adsb=' + adsb;
|
var mapUrl = '/map/index.html' + apiUrl + '&associator=' + associator + '&coordreg=' + coordreg + '&adsb=' + adsb;
|
||||||
|
|
||||||
// Redirect to the constructed URL
|
// Redirect to the constructed URL
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Message:
|
||||||
with conn:
|
with conn:
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
data = conn.recv(65000)
|
data = conn.recv(8096)
|
||||||
if not data:
|
if not data:
|
||||||
break
|
break
|
||||||
decoded_data = data.decode()
|
decoded_data = data.decode()
|
||||||
|
@ -82,7 +82,7 @@ class Message:
|
||||||
try:
|
try:
|
||||||
client_socket.connect((self.host, self.port))
|
client_socket.connect((self.host, self.port))
|
||||||
client_socket.sendall(message.encode())
|
client_socket.sendall(message.encode())
|
||||||
reply = client_socket.recv(65000).decode()
|
reply = client_socket.recv(8096).decode()
|
||||||
return reply
|
return reply
|
||||||
except ConnectionRefusedError:
|
except ConnectionRefusedError:
|
||||||
print(f"Connection to {self.host}:{self.port} refused.")
|
print(f"Connection to {self.host}:{self.port} refused.")
|
||||||
|
|
|
@ -181,7 +181,10 @@ async def callback_message_received(msg):
|
||||||
api[-1]["server"] = [api[-1]["server"]]
|
api[-1]["server"] = [api[-1]["server"]]
|
||||||
|
|
||||||
# json dump
|
# json dump
|
||||||
output = json.dumps(api)
|
for item in api:
|
||||||
|
if item["hash"] == short_hash(msg):
|
||||||
|
output = json.dumps(item)
|
||||||
|
break
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue