[英]WebSocket server can't receive message sended from ios client
我使用ws實現WebSocket服務器,並成功將消息發送到ios客戶端(使用SocketRocket )。但是我無法將消息發送到服務器,或者服務器可能無法接收從ios客戶端發送的消息。
WebSocket服務器:
const WebSocket = require('ws');
const wss = new WebSocket.Server({port: 8080});
wss.on("connection", function connection(ws) {
ws.on('message,', function incoming(message) {
console.log('received: %s', message);
});
ws.send("something");
});
我想實現一個可以與ios客戶端交換數據的websocket服務器。
wss.on("connection", function connection(ws) { ws.on('message', function(message) { console.log('received: %s', message); }); ws.send("something"); });
看一下回調on('message',
您正在定義一個函數,不是普通的匿名函數用作回調,它也是message
而不是message,
(請注意逗號)。
嘗試使用示例回顯服務器,以確保一切正常,並且使用iOS客戶端,並且您沒有任何奇怪的問題,然后繼續進行進一步的處理。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.