网友回复
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%
python如何实现声纹识别用户进行验证?
在哪可找到各种影视经典角色的配音并克隆音色根据文本说话?
阿里通义大模型哪些是支持多模态的api的ai模型?
js如何实现浏览器中离线语音唤醒语音聊天小助手?
浏览器中如何将WebM视频转成mp4视频?
parlant如何改成qwen 的apikey与baseurl?
如何写一个chrome插件实现截屏自动生成步骤图文教程转成pdf或网页?
python如何通过阿里云的api对域名进行解析和ecs主机服务器进行启动停止等操作?
Tesla Robotaxi可以让特斯拉车自动无人驾驶跑滴滴为车主赚钱,国内以后也会这样吗?
有没有可以监控安卓手机上的app打开后偷偷摸摸做了啥的监控软件?