netbeast/react-native-ssdp

Help to bring this library, work as expected in react-native apps.

RajeshSivanesan opened this issue · 11 comments

Library installation showed linking process, but there were no android / iOS directories in the project to help linking native modules to the application.

Business Case:
Use SSDP client where I can search for endpoints supporting a specific service type (ST).
Client was initialized without any extra parameters (since I want to default it to ssdpIp & ssdpPort)

Problems Faced:

Cannot resolve module dgram(To fix this, installed react-native-udp and link process, since library was using dgram from nativemodules of RN)

After solving this, got error like 'getIPAddress' method invoked on undefined object. Because it required another native module react-native-network-info & link process.

Post successful loading of files, without error. I got some console messages while debugging namely
"socket-1 binding, address: 0.0.0.0 port: 0"
"socket-1 bound to address: 0.0.0.0 port: 0"
"WebSocket error [object Object]"

While debugging, error object was undefined, was not able to derive what was I missing ?

Versions Used:
"react-native": "0.40.0",
"react-native-ssdp": "^2.7.5",
"react-native-udp": "^1.2.9",

Let me know whether these additional installation processes are required, to make it
load without errors ?
& Let me know how to bring this to working condition.

Won't I be able to access SSDP client alone as a library ? Do I need to run a server which binds to a socket and client will always connect and send messages to that alone ?

@RajeshSivanesan thanks for the issue. All the steps you mentioned are right (we are using this library in production) I guess you can create a PR to this repo with some docs.

About the SSDP client as a library I believe the protocol uses multicast UDP to listen for devices in the network, so you will need a multicast socket in both cases.

@jsdario, Thanks for the reply.

I will try to add that doc regarding the setup process.

I tried editing react-native-udp core java files like udpsocket.java, but the output was not working as expected.

I saw some Examples of ios Swift where in they use clients sockets to send messages to an ip address and port number, they don't need an binding step.

Can you let me know how a udp socket Client works? Do Client sockets need to bind to a address? Can you let me know my understanding is right?

@jsdario

I found one more issue, where Buffer is been used by udpsockets internally and it requires to in global instance.

Post reading react-native-udp document, I came to know this. Which took me 2 days to figure out this.

Since Buffer was undefined in my code, response could not be parsed properly due to format issue and hence i didn't receive any response from the library.

If possible, you can add them to the readme.md file also.

@RajeshSivanesan hI,

EDIT: Thanks for the PR, merged now #4
Added you to CONTRIBUTORS.txt.

UDP sockets are just like TCP sockets, except that in TCP there is always one listening to opening new TCP connections attached to the main listener. In SSDP (normally) you will open 1 UDP socket for both the DISCOVERY primitive and listening for ITS response.

After inspecting the code I confirmed those aspects, but I did not write it, so I could be wrong about this particular implementation of the protocol.

Note: Make sure you close all the sockets you open before trying to reopen them: that will cause the OS to crush your process.

Feel free to close this issue or comment if you feel we can close it.

tohjg commented

i'm using rn 0.41.2, react 15.4.0.

when i tried var Buffer = require('buffer/') or global.Buffer = require('buffer/') in react-native-udp, an error message saying "Buffer.isBuffer is not a function" while calling respondToSearch method. how did you get it right, @RajeshSivanesan ?

after i traced out message while parsing message returning from udp socket, i found out it's uint8array. i used text-encoding's TextDecoder to decode the message. then it works, but it take some times for react native packager to transform modules.

Hi @tohjg, I solved it by assigning global.Buffer = require('buffer/') before requiring react-native-udp.

@tohjg

If you want to send and receive node Buffer objects, you'll have to "npm install buffer" and set it as a global for UdpSockets to pick it up.

I took the above statements from react-native-udp documentation. As per @jsdario statement it should work finer.

tohjg commented

i just added PR #6 for better and clearer installation

tohjg commented

i just added another PR #7. it would be a bad idea to assign variable as global. some other javascript might accidentally override it.

Nice, thanks for all the submissions.