mirror of
https://github.com/th3r00t/pyShelf.git
synced 2026-04-28 01:59:35 -04:00
Websocket connection, w bi-directional transport complete
This commit is contained in:
@@ -21,9 +21,12 @@ async def echo(websocket, path):
|
|||||||
tx = pong(message)
|
tx = pong(message)
|
||||||
await websocket.send(tx)
|
await websocket.send(tx)
|
||||||
|
|
||||||
|
|
||||||
def pong(message):
|
def pong(message):
|
||||||
|
print('Ping Received')
|
||||||
return "pong"
|
return "pong"
|
||||||
|
|
||||||
|
|
||||||
start_server = websockets.serve(echo, "127.0.0.1", 1337)
|
start_server = websockets.serve(echo, "127.0.0.1", 1337)
|
||||||
|
|
||||||
asyncio.get_event_loop().run_until_complete(start_server)
|
asyncio.get_event_loop().run_until_complete(start_server)
|
||||||
|
|||||||
@@ -172,8 +172,8 @@ $(document).ready(function(){
|
|||||||
});
|
});
|
||||||
$(document).on('click', '.logout-btn', function(){window.location.href = '/logout'});
|
$(document).on('click', '.logout-btn', function(){window.location.href = '/logout'});
|
||||||
$(document).on('click', '.import-btn', function(){
|
$(document).on('click', '.import-btn', function(){
|
||||||
let socket = PyshelfServer(server);
|
let connection = PyshelfServer(server);
|
||||||
ping(socket);
|
//ping(socket);
|
||||||
});
|
});
|
||||||
$('#coll_button').on('click', function(){
|
$('#coll_button').on('click', function(){
|
||||||
var isopen = $('#pop_over_0').dialog("isOpen");
|
var isopen = $('#pop_over_0').dialog("isOpen");
|
||||||
@@ -271,9 +271,9 @@ function resize_search(win_width){
|
|||||||
function OpenSocket(address) {
|
function OpenSocket(address) {
|
||||||
return new Promise(resolve => {
|
return new Promise(resolve => {
|
||||||
const connection = new WebSocket(address);
|
const connection = new WebSocket(address);
|
||||||
connection.onconnect = function(e){
|
connection.onopen = function(e){
|
||||||
|
console.log('--[ Connection Established ]')
|
||||||
ping(connection);
|
ping(connection)
|
||||||
};
|
};
|
||||||
connection.onmessage = function(rcvd){
|
connection.onmessage = function(rcvd){
|
||||||
sock_rx(rcvd)
|
sock_rx(rcvd)
|
||||||
@@ -283,9 +283,7 @@ function OpenSocket(address) {
|
|||||||
}
|
}
|
||||||
async function PyshelfServer(address){
|
async function PyshelfServer(address){
|
||||||
console.log("--[ Starting Connection ]")
|
console.log("--[ Starting Connection ]")
|
||||||
connection = await OpenSocket(address);
|
return await OpenSocket(address)
|
||||||
console.log('--[ Connection Established ]')
|
|
||||||
return connection
|
|
||||||
}
|
}
|
||||||
function sock_rx(rcvd) {
|
function sock_rx(rcvd) {
|
||||||
if (rcvd.data == 'pong') { pong(rcvd.data) }
|
if (rcvd.data == 'pong') { pong(rcvd.data) }
|
||||||
@@ -297,8 +295,9 @@ function sock_status(connection) {
|
|||||||
return [buffered, ready];
|
return [buffered, ready];
|
||||||
}
|
}
|
||||||
function ping(connection) {
|
function ping(connection) {
|
||||||
connection.send('ping')
|
connection.send('ping');
|
||||||
|
console.log("[ping]>>");
|
||||||
}
|
}
|
||||||
function pong(rcvd) {
|
function pong(rcvd) {
|
||||||
console.log("<<["+rcvd.data+"] "+rcvd.data)
|
console.log("<<["+rcvd+"]")
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user