如何使用telnet调用javascript中的变量

问题描述 投票:1回答:1

我有一个包含多个页面的网站。我的网站未托管,可通过xampp localhost查看。我想知道当从远程telnet接收到标记图标下面的图标代码的MuteOn时,如何调用变量将颜色更改为红色,而当从远程telnet接收到MuteOn时,如何将变量更改为绿色。这也是我当前的telnet javascript连接代码。我最终希望我的server.js具有接收命令的功能,然后将其实现到我的网页。

Server.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相当陌生,因此非常感谢所有信息。谢谢!

javascript html css telnet
1个回答
2
投票

您需要像express这样的东西来调整和提供HTML。 Telnet使用与HTTP协议不同的TCP协议。

© www.soinside.com 2019 - 2024. All rights reserved.