mirror of
https://github.com/zeek/zeek.git
synced 2025-10-02 14:48:21 +00:00
Copy docs into Zeek repo directly
This is based on commit 2731def9159247e6da8a3191783c89683363689c from the zeek-docs repo.
This commit is contained in:
parent
83f1e74643
commit
ded98cd373
1074 changed files with 169319 additions and 0 deletions
23
doc/devel/websocket-api/server.js
Normal file
23
doc/devel/websocket-api/server.js
Normal file
|
@ -0,0 +1,23 @@
|
|||
// server.js
|
||||
import WebSocket, { WebSocketServer } from 'ws';
|
||||
|
||||
const wss = new WebSocketServer({ port: 8080 });
|
||||
|
||||
wss.on('connection', (ws, req) => {
|
||||
ws.on('error', console.error);
|
||||
ws.on('close', () => { console.log('%s: gone', ws.zeek.app); });
|
||||
|
||||
ws.on('message', function message(data) {
|
||||
console.log('%s: received: %s', ws.zeek.app, data);
|
||||
});
|
||||
|
||||
let topics = ['zeek.bridge.test'];
|
||||
let app = req.headers['x-application-name'] || '<unknown application>'
|
||||
ws.zeek = {
|
||||
app: app,
|
||||
topics: topics,
|
||||
};
|
||||
|
||||
console.log(`${app}: connected, sending topics array ${JSON.stringify(topics)}`);
|
||||
ws.send(JSON.stringify(topics));
|
||||
});
|
15
doc/devel/websocket-api/server.zeek
Normal file
15
doc/devel/websocket-api/server.zeek
Normal file
|
@ -0,0 +1,15 @@
|
|||
global hello: event(c : count);
|
||||
|
||||
global c = 0;
|
||||
|
||||
event tick()
|
||||
{
|
||||
Cluster::publish("zeek.bridge.test", hello, ++c);
|
||||
schedule 1.0sec { tick() };
|
||||
}
|
||||
|
||||
event zeek_init()
|
||||
{
|
||||
Cluster::listen_websocket([$listen_addr=127.0.0.1, $listen_port=8000/tcp]);
|
||||
event tick();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue