【发布时间】:2020-08-03 11:38:46
【问题描述】:
我有一个包含多个页面的网站。我的网站没有托管,通过 xampp localhost 查看。我想知道如何调用变量以在收到 Mute 时将颜色更改为红色,当从远程 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 相当陌生,因此非常感谢所有信息。谢谢!
【问题讨论】:
-
那么你网站的操作完全不涉及HTTP和浏览器?
-
确实如此,我通过 localhost 在 google chrome 上运行它。希望这有助于@AvivLo
-
你需要类似 express 的东西来处理和提供 html
-
没有问题。我应该添加答案吗?
-
是的,请@AvivLo
标签: javascript html css telnet