simple nodejs tcp server on pi; which ip address to use - Raspberry Pi Forums


here simplest nodejs tcp server running on pi

code: select all

var net = require('net'); var server = net.createserver(function (socket) {   socket.on('data',function(data){      if(data.tostring()=='hello'){           console.log('take photo');       }   }); }); server.listen(1337, '127.0.0.1');  
, command `netstat -an` showing listening @ address: 127.0.0.1, port 1337.

connect tcp server machine on local lan, tried connect ip address, happens "192.168.1.10". got error 10061: "no connection made because target machine actively refused it"

if changed nodejs script

code: select all

server.listen(1337, '192.168.1.10');
other machine can connect it.

question how make nodejs script binding "localhost". tcp server still visible on local lan.

reason ip address '192.168.1.10' dynamically assigned in local lan. don't want fix in nodejs script.

try:

server.listen(1337, '0.0.0.0');

bind active ip interfaces. should able connect on network no matter ip address rpi assigned.

i'd use port number until sort of thing figured out.


raspberrypi



Comments

Popular posts from this blog

VIDIOC_S_FMT error 16, Device or resource busy - Raspberry Pi Forums

using a laptop skeleton to build a pi laptop - Raspberry Pi Forums

Forum for Joomla? - Joomla! Forum - community, help and support