簡體   English   中英

在canvas中上傳圖像文件,並使用node.js中的socket.emit將其廣播到客戶端

[英]Uploading image file in canvas and broadcasting it to clients using socket.emit in node.js

我只想將圖像從服務器廣播到客戶端。

我可以將圖片上傳到客戶端的一端。 但是它沒有在另一面反映出來。 為了使這些功能正常工作,我必須包括哪些代碼片段?

我認為您不應該將Socket.IO用於高負載流傳輸(如圖片)。

嘗試這個:

在您的服務器中:

var socket = require('socket.io'),
    io = socket.listen(yourApp);

io.sockets.on('connection', function(client) {

  client.on('imageUploaded', function(imgURL) {
    client.broadcast.emit('imageBroadcast', imgURL);    
  });

});

在您的客戶中:

var server = io.connect(yourServerIp);

// You image upload logic here. You can get the URL after uploading and then you call this function:
function imageUploaded(url){
  server.emit('imageUploaded', url);
}

server.on('imageBroadcast', function(imgURL){
  // Here you decide what to do with the image
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM