簡體   English   中英

如何使用 telnet 在 javascript 中調用變量

[英]How to call variable in javascript using telnet

我有一個由多個頁面組成的網站。 我的網站沒有托管,通過 xampp localhost 查看。 我想知道如何調用變量以在收到靜音時將顏色更改為紅色,並在從遠程 telnet 收到 MuteOn 時將顏色更改為綠色,以便標記圖標下方的圖標代碼。 也是我當前的 telnet javascript 連接代碼。 我最終希望我的 server.js 讓 function 接收命令,然后將它們實現到我的網頁。

服務器.js:

// Include Nodejs' net module.
const Net = require('net');
// The port on which the server is listening.
const port = 50000;
// Use net.createServer() in your code. This is just for illustration purpose.
// Create a new TCP server.
const server = new Net.Server();
// The server listens to a socket for a client to make a connection request.
// Think of a socket as an end point.
server.listen(port, function() {
    console.log(`Server listening for connection requests on socket localhost:${port}`.);
});
// When a client requests a connection with the server, the server creates a new
// socket dedicated to that client.
server.on('connection', function(socket) {
    console.log('A new connection has been established.');
    // Now that a TCP connection has been established, the server can send data to
    // the client by writing to its socket.
    socket.write('Hello, client.');
    // The server can also receive data from the client by reading from its socket.
    socket.on('data', function(chunk) {
        console.log(`Data received from client: ${chunk.toString()`.});
    });
    // When the client requests to end the TCP connection with the server, the server
    // ends the connection.
    socket.on('end', function() {
        console.log('Closing connection with the client');
    });
    // Don't forget to catch error, for your own sake.
    socket.on('error', function(err) {
        console.log(`Error: ${err}`);
    });
});

圖標代碼:

<!DOCTYPE html>
<html>
<head>
<link rel="stylesheet" type="text/css" href="fonts/font-awesome-4.7.0/css/font-awesome.min.css">
<script src="https://kit.fontawesome.com/a076d05399.js"></script>
</head>
<body>

<div class="flex-w flex-c-m p-t-5 p-b-0">
<a href="#" class="flex-c-m how-social trans-04 m-r-50 m-l-50 m-b-5">
<i class='fas fa-volume-up' style='font-size:95px;color:white'></i>
</a>

<a href="#" class="flex-c-m how-social trans-04 m-r-50 m-l-50 m-b-5">
<i class='fas fa-microphone' style='font-size:95px;color:white'></i>
</a>

<a href="#" class="flex-c-m how-social trans-04 m-r-50 m-l-50 m-b-5">
<i class='fas fa-phone-volume' style='font-size:95px;color:white'></i>
</a>

<a href="#" class="flex-c-m how-social trans-04 m-r-50 m-l-50 m-b-5">
<i class='fas fa-video' style='font-size:95px;color:white'></i>
</a>
</div>
</div>

</body>
</html>

我在設計這個網頁時使用了 html、css 和 javascript。 我對使用 telnet 相當陌生,因此非常感謝所有信息。 謝謝!

您需要諸如 express 之類的東西來調整和服務 HTML。 Telnet 使用的是與 HTTP 協議不同的 TCP 協議。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM