node.js + socket.IO sending tcp/ip messages

3,847 views
Skip to first unread message

tomfish

unread,
Mar 7, 2012, 8:54:43 AM3/7/12
to nod...@googlegroups.com
Hello,

I would like to send a command from a (local) website to a computer in the same network on a specific port. This port is in use by digital signage software. When the software receives this command, it changes the image.
Can anyone help me with this? node.js and socket.IO are already installed, but I can't seem to find the right coding.

Thanks in advance,

Tom

Evan

unread,
Mar 8, 2012, 2:11:02 AM3/8/12
to nod...@googlegroups.com
Socket.io while awesome, might be a little overkill here.  It sounds like you just need to connect to a port on a remote machine and sent some commands.  You can start up your connection like this [[ http://nodejs.org/api/net.html#net_net_connect_arguments ]] and then use the client.write() method to send your string to the remote server.

tomfish

unread,
Mar 8, 2012, 4:16:07 AM3/8/12
to nodejs
Yes I thought that Socket.IO would be a little overkill. I now know I
need to use regular sockets. But I can't seem to get this working.
I believe I need to make an html file that sends commands to my tcp
server? There is now way I can make my index.html interact with my
server.

Kind regards,
Tom

Evan

unread,
Mar 8, 2012, 12:13:25 PM3/8/12
to nod...@googlegroups.com

Ahh! I would suggest you think about the flow of your application this way which might clear things up:


- User on website loads a page, something like /changeImage.html?newImage=picture1.jpg

- nodejs server receives request for /changeImage.html and parses the GET string to find the var newImage = "picture1.jpg"

- Before returning to the user (rendering the HTML response for changeImage.html), your server (not your html) runs a method to pass the TCP command to your sign ( sendSignMessage({image = picture1.jpg}, callback) ).  sendSignMessage would connect to the digital sign (or make use of a previously initialized connection) per [[ http://nodejs.org/api/net.html#net_net_connect_arguments ]]

- sendSignMessage() waits until it receives a response from the sign and passes that message on to the callback passed to it, which in turn should finally render out (with that response included) to the user on the website.


There are a few reasons for this type of architecture:

- While I haven't done much work with digital signs, I have interfaced with a lot of lighting control hardware, and those devices have trouble dealing with lots of connections.  Having your server maintain one connection which is a proxy for all of your web users is useful

- It's really hard (and often times impossible) to get javascript in the browser to connect to arbitrary ports

- It's also really hard (even with websocckets) to have javascript in the browser act as a raw TCP connection to send arbitrary messages to a server that isn't the same as the webserver (cross domain problems)

Alexandre RAOUL

unread,
Mar 8, 2012, 3:54:31 PM3/8/12
to nod...@googlegroups.com
Hi,

I'm currently using node & socket.io as a proxy for accessing to an old legacy app running on sockets.

It is in very very early state but it's working, take it as a proof of concept, not as a ruggedized app (it doesn't auto reconnect etc)
socket io + http server http://jsfiddle.net/cnKM7/ 
basic tcp server (for testing) http://jsfiddle.net/fHy8H/ 

I removed some code and did not test after so it might be broken but it should be enough to understand how it works.



--
Job Board: http://jobs.nodejs.org/
Posting guidelines: https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to nod...@googlegroups.com
To unsubscribe from this group, send email to
nodejs+un...@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en

Reply all
Reply to author
Forward
0 new messages