如何将socket对象传递给worker线程?
发布于 7 年前 作者 xiejing 4384 次浏览 来自 官方Issues

我需要在worker线程内向外部主机发送数据,如何将udp socket传递给worker

const WORKER = wx.createWorker('/worker/WorkerSender.js');
...
udp = wx.createUDPSocket();
...
WORKER.postMessage(
        {
          sock: udp,
          data: frameBuffer
        }
      );

worker线程如下

worker.onMessage(function (res) 
{

  res.sock.send(
    {
      address: '192.168.1.8',   //'192.168.137.1',
      port: 22224,
      message: res.data
    });
});

报错说

thirdScriptError

worker uncaught third Error

TypeError

TypeError: s.sock.send is not a function… ‘s.sock.send’ is undefined

 

1 回复

不行的,worker 内无法处理 WebSocket

回到顶部