-2

I know a bit about socket.io which enables realtime bi-directional communication between client and server but I want to run two apps on the server for this purpose. I mean I don't want a user to have access over the running port from outside. (A realtime communication between two apps only)

The case is: one app should be running always and one app is executed on specific time intervals.

I'm not sure if I expressed my thoughts as I should, but I appreciate your guides if you got what I suppose to do. I don't know how I can achieve this hence the question is exactly "how"? (Tips needed)

revo
  • 47,783
  • 14
  • 74
  • 117
  • Please ask me questions if narrowing down the problem is necessary. – revo Apr 17 '16 at 17:46
  • 1
    There are [many ways](https://en.wikipedia.org/wiki/Inter-process_communication) for two processes on a server to communicate with each other. Are the processes on the same server or will they communicate over a network? Do you have any particular means of communicating in mind? As it stands your question is quite broad. – Sunil D. Apr 17 '16 at 18:15
  • @SunilD. Two apps (by app I mean a single .js file) are on the same server. I need an app be running forever (to handle emitted events) and another app for triggering events (this app is executed manually). – revo Apr 17 '16 at 18:47
  • 1
    So I think you need to just decide on a technology. Socket.io would [work just fine](http://stackoverflow.com/q/9018888/398606). Pub/sub solutions (Redis, etc.) work nicely too. While not as elegant, reading from the file system would also work... – Sunil D. Apr 17 '16 at 19:27
  • @SunilD. I appreciate your comments. Thank you. – revo Apr 17 '16 at 20:00

1 Answers1

2

You can easily use socket.io to communicate between two server-side apps. You would just set up a socket.io server on one of the server-side apps and use a non-public port number. Then, on the other server-side app, use the socket.io-client library to make a connection to the other server-side app using the same type of code you would use from a browser, but using server-side require('socket.io-client') to load the library.

Then, your two apps will be connected and you can freely send socket.io messages either direction.

FYI, there are a myriad of different technologies that can be used for communicating between two apps running on the same server. Socket.io would work just fine for that (since that's what you asked about) as would many other technologies.

jfriend00
  • 683,504
  • 96
  • 985
  • 979
  • Thank you @jfriend00. For the last part, is there any comprehensive article that you can refer me to? – revo Apr 17 '16 at 19:52
  • 1
    @revo - Personally, I'd just use socket.io or stdio (depending upon specific requirements) from your child process as both are fully cross platform and available in node.js. Many of the other options are platform variant. Here's one other post that discusses some options on Linux: http://stackoverflow.com/questions/2281204/which-linux-ipc-technique-to-use and a presentation on the topic: http://man7.org/conf/lca2013/IPC_Overview-LCA-2013-printable.pdf – jfriend00 Apr 17 '16 at 19:57