TCPClient and NodeJS server

Hi there,

I’m trying to get a Photon to communicate with a NodeJS Server, but I don’t get it to work.

I have a NodeJS server listening on port 3700 and I have this code flashed to the core:

TCPClient client;
byte server[] = { my, ip, add, res };

void setup() {
    pinMode(D7, OUTPUT);

void loop() {
    if(client.connect(server, 3700)){
        digitalWrite(D7, HIGH);

But D7 does not turn on. Does this mean I’m not connecting at all? What could be going wrong?

SOLVED: My photon could not connect because I needed to forward my port to my device in my router. For a full explanation scroll down and read rickkas7 post.

I’m not sure what the issue might be, but some of these topics might offer some help:

Thanks, I guess I’ll read those first.

Hi again, so I read the examples, and I tried them out too, but they don’t do anything for me. It seems that the photon simply does not connect to my server.

Could this be an IP issue? The applications work fine on localhost in my browser, so I assume the server is running, but all connect attempts fail.
The IP I pass to my firmware is the one I get from but other computers in my home all share that address so I can imagine that this address is not sufficient.
I just don’t know how I could solve this issue.

I can imagine you’d need the IP address from the actual device rather than from your ISP. There are several apps available with which you can scan your local network, but a look inside your router should offer the same info.

A typical home network looks something like this:

Everything on your home network is assigned an IP address on your local network, typically of the form 192.168.x.y or 10.x.y.z by your router.

In this example, the router itself has an internal IP address of, the Photon, and so on.

The router also has a connection to the rest of the Internet. All of the home devices share one public IP address, in this example it’s

When you’re doing local connection using TCP or UDP, you always use the internal IP addresses. Say you’re running a node server on the computer If the Photon wanted to make a connection, it would use TCPClient to make a connection to

If Remote Laptop, elsewhere on the Internet, wanted to access any of the internal servers, whether it be the node server on or the Photon directly, you’d need to reconfigure your router port forwarding to connection into the external address are forwarded to an internal server. You should do this with care, because it can expose internal devices to attacks from the Internet.


Alright, thank you, I looked that up after Moors7 posted about ISP and I found this:

That also mentioned port forwarding which I managed to do on my router. I tested this out using some other node.js chat example to connect to my localhost:port server on one computer from another.
This worked fine, so next I’ll be testing it out with my Photon.

Thanks for the explanation!

EDIT: worked fine on my photon as well!