网友回复
1、Electron 中使用 TCP 通信
直接引入net
// 引入 net 模块const net = window.require("net");
我们以vue为例
<template>
<div class="home">
<div>发送的消息:<input type="text" v-model="msg" /></div>
<div>接收的消息:<input type="text" v-model="msg2" /></div>
<div>
<button @click="tcpClick">发送</button>
</div>
</div>
</template>
<script>
// 引入 net 模块
const net = window.require("net");
export default {
name: "Home",
data() {
return {
client: null,
HOST: "127.0.0.1",
PORT: 7899,
msg: "",
msg2: "",
};
},
created() {},
mounted() {
// console.log(net);
this.initTcp();
this.connect(this.PORT, this.HOST);
this.data();
this.close()
// this.tcpClicent(this.PORT,this.HOST,'hellow TCP')
},
destroyed() {},
methods: {
// 初始化TCP连接
initTcp() {
this.client = new net.Socket();
},
// 当一个 socket 连接成功建立的时候触发该事件。
connect(PORT, HOST) {
this.client.connect(PORT, HOST, () => {
console.log("连接成功: " + HOST + ":" + PORT);
// 建立连接后立即向服务器发送数据,服务器将收到这些数据
this.sendMsgToTcp('hellow TCP')
});
},
// 当接收到数据的时触发该事件。
data() {
this.client.on("data", (data) => {
console.log("DATA: " + data);
this.msg2 = data;
this.destroyTcp();
});
},
// 一旦 socket 完全关闭就发出该事件, 监听连接关闭事件
close() {
this.client.on("close"...点击查看剩余70%
go如何写一个类似redis的nosql数据库让python客户端调用?
php7中为啥无法使用$_SERVER['HTTP_RAW_POST_DATA'] ?
chrome插件能否实现2台电脑的远程协助桌面控制?
python如何通过webrtc网页远程协助控制python运行的电脑?
systemd-nspawn与unshare区别?
Firejail、Bubblewrap沙箱与docker、podman容器区别?
如何访问unshare -n -- python3 -m http.server 8000创建的网站url?
linux中如何限制进程执行非法的系统调用命令,例如reboot 删除等等?
pivot_root与chroot有啥区别?
linux中如何限制进程使用cpu、内存、网络的最大值?


