Skip to content

Commit

Permalink
added socket-io impl
Browse files Browse the repository at this point in the history
  • Loading branch information
Amith Koujalgi committed Oct 18, 2023
1 parent 7899bcf commit b26067c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 3 deletions.
12 changes: 10 additions & 2 deletions sys_stats/socketio_impl/main.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import os
import threading
import time
from pathlib import Path

import eventlet
Expand All @@ -25,11 +27,17 @@ def my_action(sid, data):
print('Received message:', data)


def watcher(client):
while True:
print('watching')
client.emit("process-list", stats.processes(search_keyword=''))
time.sleep(1)


@sio.on('list_processes')
def list_processes(sid, data):
prc_list = stats.processes(search_keyword='')
sio.emit("process-list", stats.processes(search_keyword=''))
print('Received message:', data)
sio.emit("process-list", prc_list)


@sio.event
Expand Down
6 changes: 5 additions & 1 deletion sys_stats/socketio_impl/static/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,9 +13,13 @@ $(document).ready(function () {
console.log('Loaded socketio script');
socket.on('connect', () => {
console.log('Connected to server!');
socket.emit('list_processes', {data: 'foo!', id: 123});
// socket.emit('list_processes', {data: 'foo!', id: 123});
});

setInterval(function () {
socket.emit('list_processes', {search_keyword: ''});
}, 1000);

socket.on("process-list", data => {
// console.log("prc: " + JSON.stringify(data))
let processList = data;
Expand Down

0 comments on commit b26067c

Please sign in to comment.