Sending commands via Telnet/TCP to web page (Node.js) - javascript

I'm new to node.js
To illustrate my question, I'll use an example:
Client sends a command via telnet/tcp to socket server (ie 'telnet 192.168.0.10 8888' then 'showDiv1')
Command is forwarded from server to a Web page
depending on command, different are displayed on the web page
There are plenty of examples on the node.js website, but it seems difficult to combine the sample scripts to produce the desired functionality above. Any ideas?

Related

Using node.js for a server on a websocket site

I have built a simple chat application using websockets as well as the node.js program.
The website at the moment only works on my own computer - if I open multiple tabs or browsers I can send messages which would appear on all the other open tabs.
I now want to publish the site on a server so other people can use it to chat from other devices.
I know how to publish this on a server, however I do not know how to publish it so it keeps working because at the moment I have to use the node.js program to run a java script file which makes it listen on a port. Obviously if I publish the site to a server, I won't be able to keep on prompting the node program to listen for the port.
So my question is - how do I publish this site to the server? Can I use node.js program with it? My server is filezilla where I transfer the files to.
Thanks

Accessing Bloomberg API from client's browser in javascript

Is it possible to access blpapi from javascript running in the client's browser?
I wish to access bloomberg's API from javascript running in the client's browser, in the assumption that the client has an open bloomberg session and therefore bbcomm is running.
Conceptually, this would be the same as accessing the blpapi on the client side from python.
However, all existing solutions I found in js appear to be server-side:
blpapi-node (node-based)
blpapi-httm (creates a server where to post http request)
blpapi-react (cannot make this module work)
Now you can access Bloomberg data natively in JavaScript via Web AppPortal. This allows you to write web based applications that run inside LP Components.
To learn more about Web AppPortal, go to MYAP 5
To download the SDK, please type SDK -> select SDK -> AppPortal Web SDK -> click Install.
This is obsolete, see Mourad Barakat's answer above
Conversation with Bloomberg Support confirms this is not possible**
BB say they don't support javascript access, and that one solution is to use their Server API to use the authentication of the client (who has a bb terminal open) to query data and return it to the client
An alternative hack
An alternative hack is to create an executable mini-server that the client downloads and launches, and that offers an http interface to get data to the webapp.
For example, this could be done in Flask in Python, and in fact it has already been done by blpapi-web (excluding the executable part, for which you can use PyInstaller and py2exe for Windows and py2app for Mac)

Run JavaScript command on website

I have a home automation system which has a small Linux server and an app to control my lighting system. The problem is that this system is too limited for my use, so I wanted to create a desktop app (Java or C#) to send my own data to the server.
When I log into the webpage, I can just use FireFox' JavaScript console to send the commands. But my question is how I can log into a webpage and send JavaScript data to it programmatically.
I also tried sending the data through a WebSocket or TcpClient, but I have no idea how that works.
You just have to perform the same requests than the browser when you are on the website, that is (most probably) HTTP GET and HTTP POST. It is possible to send the request with any programming language, including JavaScript.

How to give Node.js server a command from php script?

sorry to bother you, but I've been looking for answers and I couldn't find them anywhere... Well i'm a fresh dude in the field of javascript and node.js and here's my problem:
I've created an application based on the tutorial of socket.io - Here's the link to the completed project of their chat example. everything is working as it should, but I would really need to trigger somekind of a command while node server is running... command should be triggered via php script.
The command should trigger an emit event - so every client in our case would see a new message sent via php.
I saw couple of suggestions to do it from another server with php/using cURL. The problem is that I don't know how to fetch POST data sent from php to node.js server.
Any solution to command node with php is more than welcome and again i'm sorry to bother you :)
You can use a bridge to exchange data between NodeJS and PHP. You will need to implement a PHP server that exposes remote procedures and a NodeJS client that calls those remote procedures. You can send any data to the NodeJS application from PHP using these remote procedures.
Here are a few links to get you started:
http://bergie.iki.fi/blog/dnode-make_php_and_node-js_talk_to_each_other/
https://github.com/bergie/dnode-php

NodeJS chat server interacting with non-node hosted html page

The node.js chat example is ubiquitous. However, they all serve the static html page with which the chat feature is integrated.
What about an html page that is served via apache, php, .net, or other which interacts with a node.js based chat server. How would this be implemented?
For instance, the html page contains a form used to login. The form's action points to the node server which provides the authentication and message handling. How does this chat server communicate with the client-side when it is not also providing the static html content?
Yes, it's possible. If I understand you correctly, you'll probably want to use this approach:
Run the apache server on a different port from the node.js server, and have the static server serve the chat page. Then, you have two main options for how to get data from the static page to the node.js server: either use XMLHttpRequest directly from the static page with CORS (you'll need it because you're running from different ports, but it's still possible to have CORS allow from different ports on the same domain but nothing else, so it can still be secure), or have an invisible iframe of the node.js page on the static page, and then send data to it with postMessage, and then the iframe (which is on the same port as the node.js server, as it's being served by node.js) will forward the data from the postMessage to the server with XMLHttpRequest
You can also do a proxy, but it won't be as good for this type of situation I think, because if Apache is running the proxy, it completely erases how node.js does well with comet and things, but if you run node.js as the main server proxying to Apache, it would be easier just to do everything with node, so I'm guessing you don't want that
Here is a simple solution I found that works to add socket.io real-time interactivity to any existing html page, even when that page is hosted on another server.
Include a reference to socket.io in the head of the html page. The IP address and port number should be the location of your node.js server that is running socket.io.
<script src="http://xxx.xxx.xxx.xxx:xxxx/socket.io/socket.io.js"></script>
[NOTE: localhost doesn't work, you must use the actual IP address - don't forget the port]
Then, within a script block on the same html page, open a connection to the socket:
<script>
var socket = io.connect('http://xxx.xxx.xxx.xxx:xxxx');
</script>
That's it, you're connected!

Categories