Saya menjelaskan bagaimana menerapkan mekanisme dengan jaring pengaman eksternal untuk mendorong penyegaran ke halaman APEX. Ini menggunakan Beaconpush.
Tapi saya tidak menyukai ketergantungan pada websocketserver eksternal (saya seperti itu), jadi saya menyelidiki apa yang harus dilakukan untuk mengimplementasikan websocketserver saya sendiri.
Memperkenalkan node.js
Node.js adalah platform yang dibangun di Chrome JavaScript runtime agar mudah membangun aplikasi jaringan yang cepat dan terukur. Node.js menggunakan model I / O event-driven, yang membuatnya ringan dan efisien, cocok untuk aplikasi real-time data-intensif yang berjalan di perangkat terdistribusi.
JavaScript adalah keahlian yang berkembang di antara pengembang Oracle / APEX, jadi ini adalah pilihan logis untuk melihat ke dalam menggunakan JavaScript sisi server untuk menerapkan kombinasi http / websocketserver. Idenya adalah membuat server yang sangat sederhana yang dapat dihubungkan oleh klien dengan menggunakan mekanisme websocket. Database harus bisa mengirimkan permintaan ke bagian HTTP dari server yang akan digunakan untuk klien yang terhubung.
Pasang node.js
Di situs node.js Anda dapat mendownload installer untuk node.js. Saya mendownload MSI (saya menggunakan mesin Windows 7/8/10).
Install websocket
Node.js bekerja dengan modul yang bisa dipasang. Untuk contoh ini kita membutuhkan modul websocket. Untuk menginstal, gunakan NPM yang dapat dieksekusi
npm pasang websocket
Sebagai sidenote, instalasi ini gagal pada mesin saya. Saya rasa versi node.js tidak kompatibel dengan versi websocket (1.0.4). Saya harus menginstal satu versi lebih rendah:
npm install websocket@1.0.3
Create the server.js
Seperti yang saya sebutkan sebelumnya, kita berbicara tentang JavaScript sisi server. Jadi Anda harus membuat file JavaScript, i.n. server.js
"use strict"; process.title = 'database-chat'; var config = { port:1337 }; /* We need a HTTP-server and a websocketserver */ var webSocketServer = require('websocket').server; var http = require('http'); /* We need to keep record of connected clients */ var clients = [ ]; /* The HTTP server */ var server = http.createServer( function(req, resp){ var body = ''; var json; req.setEncoding('utf8'); resp.writeHead(200,{'Content-Type':'application/json' }); req.on('data', function(data) { body += data.toString(); /* When we get a stringified JSON-object, that's oke. If not, we just create one with one attribute */ try { json = body; var test = JSON.parse(json); } catch (e) { json = JSON.stringify({ 'message':body} ); } /* Push the JSON-string to all the connected clients */ for (var i=0; i < clients.length; i++) { clients[i].sendUTF(json); } resp.end(JSON.stringify({ message: 'Send to '+ clients.length + ' clients' })); }); }); /* Start listening on the configured port an write to standard output*/ server.listen(config.port, function() { console.log((new Date()) + " Server is listening on port " + config.port);1 }); /* WebSocket server */ var wsServer = new webSocketServer({ // De WebSocket server is tied to a HTTP server. httpServer: server }); /* If a client connects to the websocketserver, this callback accepts the request and adds it to the list */ wsServer.on('request', function(request) { console.log((new Date()) + ' Websocketconnection from origin ' + request.origin + '.'); var connection = request.accept(null, request.origin); // we need to know client index to remove them on 'close' event var index = clients.push(connection) - 1; console.log((new Date()) + ' Connection accepted.'); connection.on('close', function(connection) { console.log((new Date()) + " Peer " + connection.remoteAddress + " disconnected."); clients.splice(index, 1); }); });
Start the server
Memulai script server.js ini mudah. Dalam command window type
node server.js

Tapi apa itu server tanpa client?
Pertama-tama Anda harus memiliki semacam prosedur pada database yang akan mengirim pesan ke server.js Anda
procedure push ( p_text in varchar2 ) is l_clob clob; begin l_clob := APEX_WEB_SERVICE.MAKE_REST_REQUEST ( p_url => 'http://127.0.0.1:1337' , p_method => 'POST' , p_body => '{"message":"'||p_text||'"}' ); end;
Dengan prosedur seperti itu, Anda bisa misal. dorong pesan REFRESH ke halaman Anda dan segarkan wilayahnya.
Buat halaman dengan laporan interaktif yang ingin Anda refresh.
Di footer halaman tambahkan script berikut ini:
$(function(){ window.WebSocket = window.WebSocket || window.MozWebSocket; if (!window.WebSocket) { console.log('Sorry, no websockets'); } else { var connection = new WebSocket('ws://127.0.0.1:1337'); connection.onerror = function (error) { console.log( 'Sorry, but there is some problem with your connection or the server is down.'); }; connection.onmessage = function (message) { console.log(message.data); try { var json = JSON.parse(message.data); if (json.message=='REFRESH') { gReport.pull(); } else { console.log(json.message); } } catch (e) { console.log('This is not valid JSON: ' + message.data); } }; } });
dan hanya itu.
Pikiran Anda, ini hanya satu implementasi, tapi Anda bisa mendorong setiap acara database ke halaman klien.