You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Dec 29, 2022. It is now read-only.
}
And my udpServer receive the request, as the log shown below: serverLog - recv [{"msgType":"ipRequest"}](25 bytes) from client 192.168.1.112:63912 serverLog - recv [{"msgType":"ipRequest"}](25 bytes) from client 192.168.1.112:63912 serverLog - recv [{"msgType":"ipRequest"}](25 bytes) from client 192.168.1.112:63912
And the udpServer send the answer packet to my request client, the answer code is shown as below:
var serverSocket = dgram.createSocket('udp4');
serverSocket.on('message', function(msg, rinfo){
logger.warn('recv %s(%d bytes) from client %s:%d', msg, msg.length, rinfo.address, rinfo.port);
var msgStr = String(msg);
var message = JSON.parse(msgStr);
for (var i = 0; i < message.length; i++) {
if (message[i].msgType && message[i].msgType === 'ipRequest') {
if (ackFlag){
var ip = getIPAdress();
var ipAck = [{msgType: 'ipAck', IP: ip}];
var msg = JSON.stringify(ipAck);
logger.debug('ack to client');
serverSocket.send(msg, 0, msg.length, rinfo.port, rinfo.address);
}
}
}
});
And my request client receive the answer packet, but the data is null, as shown below: Recv from socket: {"socketId":0,"data":{},"remoteAddress":"192.168.1.125","remotePort":8081} Recv from socket: {"socketId":0,"data":{},"remoteAddress":"192.168.1.125","remotePort":8081}
the data field is null, but my expected data is "var ipAck = [{msgType: 'ipAck', IP: ip}];"
Anyone who can show me why? Thanks very much!!!
By the way, the request client is a cordova app, and is tested on IPad
The text was updated successfully, but these errors were encountered:
shansjlin
changed the title
receive udp packet data is null
receive udp packet data field is null
Nov 1, 2016
Hopefully your UDP Server send function is working..... maybe used a UDP network monitor like PAcketSender to check....
In your receive event handler, I think your missed a step to get the data out of the info object and then reconvert it from a byte array to a string for the JSON handler.
receiveListener(info) {
let self = this;
data_string = self.arrayBuffertoString(info.data) //to be written - many examples out there.
console.log('wifiStore Recv from socket: ' + data_string);
}
My code is shown as below, I create udp socket, set broadcast, bind receiveListener,and then send my request packet ipRequest to my udpServer:
}
And my udpServer receive the request, as the log shown below:
serverLog - recv [{"msgType":"ipRequest"}](25 bytes) from client 192.168.1.112:63912 serverLog - recv [{"msgType":"ipRequest"}](25 bytes) from client 192.168.1.112:63912 serverLog - recv [{"msgType":"ipRequest"}](25 bytes) from client 192.168.1.112:63912
And the udpServer send the answer packet to my request client, the answer code is shown as below:
});
And my request client receive the answer packet, but the data is null, as shown below:
Recv from socket: {"socketId":0,"data":{},"remoteAddress":"192.168.1.125","remotePort":8081} Recv from socket: {"socketId":0,"data":{},"remoteAddress":"192.168.1.125","remotePort":8081}
the data field is null, but my expected data is "var ipAck = [{msgType: 'ipAck', IP: ip}];"
Anyone who can show me why? Thanks very much!!!
By the way, the request client is a cordova app, and is tested on IPad
The text was updated successfully, but these errors were encountered: