const tcpSocket = wx.createTCPSocket()
tcpSocket.connect({
address: '192.168.8.107', // FFmpeg 推流的 IP 地址
port: 12345});
tcpSocket.onConnect((res) => {
console.log('TCP connection established',res);
});
tcpSocket.onMessage((data) => {
console.log("返回",JSON.stringify(data));
// 处理接收到的数据流
});
tcpSocket.onClose((res) => {
console.log('TCP connection closed',res);
});
tcpSocket.onError((err) => {
console.error('TCP connection error', err);
});
this.tcpSocket = tcpSocket;
onConnect 返回了 TCP connection established 352 后面数字每次都不一样 ,不知道是什么意思,文档没写,是临时端口吗?
onMessage 返回的结果是这样的,真机和开发工具都是这样 {"remoteInfo":{"address":"192.168.8.107","family":"IPv4","port":12345},"localInfo":{"address":"192.168.8.107","family":"IPv4","port":55662},"size":21,"message":{}}
而且onMessage只进了第一次而且数据是空的, socket.on 里面的一次没进,里面获取的是ffmpeg的推流,明明获取到了数据流一直在执行,但是小程序onMessage回调不进
=> {
console.error('TCP connection error', err);
});
z h
const net = require('net');
// 创建一个 TCP 服务器
const server = net.createServer(socket => {
console.log('Client connected:', socket.remoteAddress,
socket.remotePort);
socket.write("哈哈哈哈哈哈哈");
// 监听客户端发来的数据
socket.on('data', data => {
if (socket.remoteAddress === '192.168.31.194') {
console.log('Received data:', data.toString());
}
socket.write("哈哈哈哈哈哈哈");
// 回复客户端
});
// 监听连接断开事件
socket.on('close', () => {
console.log('Client disconnected');
});
// 监听错误事件
socket.on('error', err => {
console.error('Socket error:', err.message);
});
});
// 监听指定端口
const port = 12345;
const hostname = '0.0.0.0'; // 监听所有网络接口
server.listen(port, hostname, () => {
console.log(`Server listening on ${hostname}:${port}`);
});
你好,麻烦提供出现问题的具体机型、微信版本号、系统版本号,以及能复现问题的代码片段(https://developers.weixin.qq.com/miniprogram/dev/devtools/minicode.html)