Open shansjlin opened 7 years ago
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); }
@charliemciver Thanks very much. It works as you said. Info.data need to be reconverted from arrayBuffer to string. Thanks, you are so great.
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