Remote control with nodejs and cordova - node.js

I want to create a sort of remote control from my smartphone to my pc. I've created a server in my pc written with nodejs (using expressjs) and listening in a port. I want to make an app for my smartphone with cordova but I don't know how the app can know automatically the ip address of the server running in pc in my local network.

To my knowledge the best approach is to create a UDP server listening for broadcasts and send an UDP broadcast to the network segment from your APP. I have this working with Python. As long as your local router/access point is not blocking UDP broadcasts you should be fine.

Related

TCP socket communication in NodeJS

The TCP socket programming code for NodeJs given at [link][1] works fine when server and client are on the same computer.
However when I run the client and server on two separate computers connected with a single Ethernet cable to the two Ethernet ports of the two computers, the client is unable to connect to the server! The have disabled the firewall on the server which is a 64 bit Windows 10 machine. The client is a 32 bit windows 7 old machine . When I start the server it starts, but when I connect the client with the IP address of the server and correct port number, it gives ECONNREFUSED error on the client)!
I am able to ping the two computers from each other. Also a Java based simple socket client and server programs are able to communicate with each other on the connection. But the NodeJs based TCP socket program given above doesn't work across the two computers. Any idea what could be the problem.
[1]: https://www.hacksparrow.com/nodejs/tcp-socket-programming-in-node-js.html

NodeJs - how to use socket.io to send tcp packet to another computer in local area network

I have NodeJs web service in based web socket. One of my file by the server side tries send xml to printer in local area network on ip address 192.168.1.5 but this ip is in my physical network not in area network by server side. When I open the web service on localhost it's work but when I open my service via network it's not work. How can I use web socket that nodejs app will send xml via TCP to another localhost in local area network using socket client just like me?
for example (my local area network):
localhost - 192.168.1.100
printer - 192.168.1.5
localhost (my physical computer) -> opening web service (NodeJS) on browser -> running script (service) -> sending xml via TCP to printer (192.168.1.5)
is this scenario possible?
You can't directly use webSocket or socket.io to send a plain TCP packet. webocket is its own protocol and socket.io runs on top of webSocket. It initiates a connection with an http request, uses it's own data format framing and its own security scheme. As such a webSocket client can only connect to a webSocket server or a socket.io client to a socket.io server, not to a plain TCP device.
You can use the Net module in node.js to make plain TCP connections. So, you can contact the printer directly from node.js if that would work.
But, you can't make plain TCP connections directly form a browser web page without using some sort of browser plug-in that has access to native code or without sending some sort of http or webSocket or socket.io request to a server and having the server contact the printer on your behalf (which would require server and printer to be on the same local network).

Send request from Webserver to Local server

I have a nodejs webserver running on a vserver (rented by me) and a local Raspberry Pi node server.
I dont want to open any ports for beeing accesable from the webserver.
My problem is that I want to create a web application you can interact with and the rpi should do things when any button is pressed on the webserver.
I thought it would be smart to create a json file on the webserver and my local server would listen on the json file.
Is there any better Idea?
Thx for your advice!
your problem can be solved using reverse proxy softwares that establishes secure tunnels from a public endpoint such as internet to a locally running network service.
ngrok is one of the best that I prefer to use.
To establish a communication between the raspberry and the webserver you need to open a port on the webserver.
However, you can restrict it to allow connections from the raspberry pi IP address only. Or do the connection via ssh and let the raspberry pi authenticate using its public key.

What is the best way to test a video chat application locally?

If I am running a local server that is hosting a video chat application what is the best way to test the application with another user? Lets say I have two computers, is there a way I can allow computer B to connect to the local server that is running on computer A? The goal is to simply test whether the video chat application works properly in two completely different browsers running on separate computers. If there is a way I can trick the app into thinking the computer that is running the local server is another host, please let me know.
But Remember that the app needs access to the computers webcam. Thanks!
Addition Info: Nodejs application that uses the Tokbox, express, and socket.io APIs
Just make sure your web server is listening on a routable IP like "0.0.0.0", which you specify when you call http.createServer(port, ip, handler). Then point the browsers at the server's IP address such as http://192.168.1.1:3000 (fill in your specific IP and port). You can use the command ifconfig -a on linux or osx to get your server's local IP address, and ipconfig on windows.

adding lan support in a HTML5 game using javascript

i want to add lan support to tic-tac-toe game which is a HTML5 canvas based, so that two players can easily play. how can i do it using javascript/node.js?
OK, I'm assuming all of your HTML5 game is finished and you're distributing it with the server that hosts it. (Otherwise you're stuck to just the browser, which can't do all the awesome node.js net stuff, I am describing.)
NB: You need to have node.js running on both clients. Otherwise you can't do LAN-only without a central server's involvement.
One of your clients has decided they want to host a LAN game
The node.js server running on that client starts to listen on a port
That server find out its local IP Get local IP address in node.js
Options:
Your players can manually tell each other the IP of the hosting server
Your hosting server sends out broadcast messages to its local subnet, informing them that it's hosting a game
Your other client server scans for IPs in its local subnet to find any hosting gameservers (Tries to open the pre-determined port your hosting server is listening on.)
The other node.js client opens a connection to the hosting server.
Done.

Resources