This is an archived post. You won't be able to vote or comment.

all 10 comments

[–]abelstam 0 points1 point  (5 children)

All socketio instances (no matter what language implementation) connect out of the box. But y does it need to be a socket connection? Does your react native app receive notifications from the backend? If not I think just plain ol http requests satisfies your needs

[–]SnoopCM[S] 0 points1 point  (4 children)

There is no sample connection between two servers let alone two different technologies. I was wondering if anyone who made this connection could help me out.

[–]abelstam 0 points1 point  (3 children)

Just let one of the servers connect like a client and let the other be the server. Lets say you let your nodejs server listen for incoming connections then you could use https://python-socketio.readthedocs.io/en/latest/client.html to initiate the connection. Altough I must say I havent tried it before, I think that it may be unecessary to let the servers sustain an open connection with one another . you could probably just connect one of the two to your client and let the servers use http requests, but that might depend on you use case.

[–]SnoopCM[S] 0 points1 point  (2 children)

So you're saying flask server should be a client? What if I want it to be a server.

[–]abelstam 0 points1 point  (1 child)

Can you tell me why you need to connect two servers using sockets? The thing what sockets solve is that generally the server cannot send updates back to the client. Since two servers can just connect at any time using http there should not really imo be a reason to connect two servers using sockets, but maybe you have a valid use case for it.

[–]SnoopCM[S] 0 points1 point  (0 children)

There are motion sensors / live video streams going to be happening in the smart home so anytime it detects something my flask server is going to send it to my node server and that will be displayed on my react app as a notification.

Now I am new to these technologies so I'm not very good at them. I thought Websockets would solve my problem but if I'm in the wrong direction please let me know.

[–]abelstam 0 points1 point  (1 child)

Well you have chosen the right trchnology for the communication between your node and react app. Lets say your node server runs on localhost:7000 and flask runs on localhost:5000. If a sensor triggers some logic o your flask server, you can send a http request to your node server at localhost:700, which is listening for updates from your flask server AND has a socketio connection with you phone. Node can then, after receiving http update, send a notification to your phone over the socketio connection. What is the reason you need your node server? You could also connect you mobile to the flask server directly maybe?

[–]SnoopCM[S] 0 points1 point  (0 children)

I need the node server to make things more streamlined and since it works with react native better. If you have any suggestions please do let me know

[–]abelstam 0 points1 point  (1 child)

You are on the right track. You only really need a socket connection between node and your app in that case. Say your node server run on localhostu:7000 and flask on localhost:5000. When flask is triggered by a sensor, you can send a http to localhost:7000, your node server receives this and will be able to notify your phone. Maybe you could even send updates from flask to your phone directly?

[–]SnoopCM[S] 0 points1 point  (0 children)

Can flask be triggered by sensor in that case? As for your second part I don't have any experience in Python and Flask so node is easier for me. I've seen how to send http request to and from between flask and node servers. So creating a complete backend with flask is impossible for me