1
的NodeJS
的index.html週期性變化HTML體在運行時的內容 -
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body></body>
</html>
app.js
我有一個簡單的UDP套接字和一個簡單的HTTP服務器:
var socket = require("dgram").createSocket("udp4");
socket.on("message", function (message, requestInfo) {
document.body.innerHTML = message; // which obviously wrong
// because the file is running on the client-side
// I'm looking for something equivalent
});
socket.bind(1247);
var http = require('http'), fs = require('fs');
fs.readFile('./index.html', function (err, html) {
http.createServer(function(request, response) {
response.writeHeader(200, {"Content-Type": "text/html"});
response.write(html);
response.end();
}).listen(1247,'xx.xx.xx.xx');
});
我正在從其他設備成功並定期(每5秒鐘)接收UDP消息。
有沒有一種方法可以在用戶每次收到UDP消息的第一個請求後更改HTML主體的內容?