Websocket NodeJS lite (no fallback) - javascript

I'm currently working with nodeJS and Socket.IO. But the problem is : i having a website who only support recent browsers and so, websockets. I really don't need a 400kb client.js.
My question is easy : is there a nodeJS module who work only with websocket ? no fallback for old browsers, no ajax fallback etc... ?

Yes. Socket.io ultimately depends on the ws module to make WebSocket connections.
You can use this module on the server side in combination with the raw WebSocket client-side API. Note that in addition to losing fallback support, you also lose socket.io's automatic reconnection feature.
Also consider that it's not just the actual browser you have support. Many people are behind firewalls/proxies that don't support or actively block WebSocket connections. So even though the browser supports the API, your user will still be unable to use your app. For this reason, you may want to consider keeping Socket.io anyway.
BTW, the client code is only 20 kB gzipped, not 400.

Related

Alternative to chrome native messaging

I want my chrome addon to connect to redis server. One of the option explored is chrome native messaging since addon/browser cannot directly connect to redis. Browser/addon can only communicate through http/websocket.
chrome native messaging seemed to be deprecated and I couldn't find chrome.runtime.connectNative or chrome.runtime.sendNativeMessage mentioned in the current version of browser. I am currently running a web server which can accept http calls from addon and communicate through redis but looking for a faster way.
What can be fastest way for addon to connect to redis?
Edit: I dont intend to publish this addon. I will be only user running this addon but I run this addon on multiple computers running on cloud.
As #Christopher rightly pointed out, native messaging is not deprecated. In fact, it is supported by pretty much all modern browsers
There is no alternative to native messaging, but I'm not sure that you would necessarily want your users to have to download, install, and configure Redis (which would be required for this to work).
Even though your question doesn't include details about how you are using Redis, I think the Chrome Storage APIs could be helpful, especially since they are just key/value pair storage. You can also use the sync storage if you want data preserved across devices.
If the Storage APIs don't fully cover your needs and you still need Redis, you could also use Chrome Storage as a caching layer between the extension and Redis. In this scenario, your background process would GET and POST data to Redis (via your web server) in the background while the extension only directly utilizes the local storage. This would sacrifice a bit of accuracy (maybe things changed between cached requests) and add a bit of complexity but would speed things up.
Side note: Redis really should not be a performance bottleneck - perhaps you need to scale up your web server or move Redis to a dedicated server/cluster?

Node.js web application browser compatibility

I heard node.js is an ideal framework for building real time web application (chatting, live feeds etc...), then i guess it involve lot of socket io connection between nodejs and client browser.
in client side do i have to use websocket(html5) in order to communicate with node.js, if that is the case, then most of the older browser won't support HTML5-Websocket.
Question :
are real time web applications built using node.js will work only with HTML5 compatible browsers.?
Many nodejs chat applications use socket.io.
socket.io has a fallback (involving pulling or Flash) for browsers not having websockets :
Socket.IO aims to make realtime apps possible in every browser and
mobile device, blurring the differences between the different
transport mechanisms. It's care-free realtime 100% in JavaScript.
The point of using socket.io is that you don't really care, you just use it and most browsers will use websockets while some won't (but they still will work as well as possible).
I heard node.js is an ideal framework for building real time web application (chatting, live >feeds etc...), then i guess it involve lot of socket io connection between nodejs and client >browser.
Yes, what you have heard is correct. It does involve a socket.io connection between client browser and the server
Read more about socket.io here
in client side do i have to use websocket(html5) in order to communicate with node.js, if >that is the case, then most of the older browser won't support HTML5-Websocket.
socket.io package of Node JS creates a WebSocket connection internally, if the client is using HTML5 enabled browser. In other browsers, it will fall back gracefully to different transport mechanisms.
Question : are real time web applications built using node.js will work only with HTML5 >compatible browsers.?
Above comments must have made clear, it will work in all supported browsers, if you use socket.io :)
See Browser support for socket.io

Streaming with JavaScript

I want to stream real-time data from a server into a JavaScript webpage. For example, if the server receives meteorological data measurements every second, I want to visualize them as a moving graph on the webpage.
Naturally, Ajax can be used for this. However, this is not what the HTTP protocol was built for. It would help to have a faster, more lightweight protocol. Ideally, a persistent TCP connection. Are there any such possibilites in modern browsers, without using additional plugins and applets? Or can this be only done with Flash, Java, etc...?
I would check out Socket.IO. It tries to make use of WebSockets, but can fall back on standard AJAX.
Modern browsers support the Websocket implementation, however as David says, in case your browser does not support it, it will fall back to Flash sockets, Ajax, iframe long polling etc. It's a high level wrapper and easy to implement. Server side you will use nodejs and socket.io, check the documentation of socket.io

Websocket library for browsers?

Are there websocket libraries (like ajax for jquery) I can use on the browsers with fallback to ajax long polling?
I found that Socket.IO implements a weird, arbitrary layer over the WebSocket protocol. I'd rather just pass raw data back and forth, so for my project, I went with web-socket-js.
web-socket-js works similarly to Socket.IO in that it reverts to using Flash sockets if WebSocket support is unavailable. Thus, it works in all the major browsers that support Flash (I tested this myself).
Just make sure you open port 843 in your firewall or you'll get a Flash security policy error. You'll probably need a script to listen on port 843 as well...I used em-websocket for the socket server, and in its readme I believe is a link to a Perl script that provides this.
Library with WebSockets support and fallback long polling solution would probably depend also on server side technology and not only browser client. Try to look at socket.io for example.
I have been using SignalR for the last several months, and it is awesome. It does what Socket.IO does, but maybe even better. It degrades as follows: Web Sockets, Server Sent Events, Forever Frame, AJAX long polling. Only works with .NET though.
https://github.com/SignalR/SignalR/wiki/Faq
Yes, you'll need server support for that as well. Kaazing WebSocket Gateway supports a very fast emulation/Polyfill. If you have a plugin like Flash it may use that (opportunistic optimization), but if you don't it emulates WebSocket with encrypted streaming, which is a lot more efficient than long polling. It comes with SSE and Cross Document Messaging support and emulation as well, as well as many higher level protocol abstractions (JMS/Stomp, XMPP, etc.)
Union Server has WebSocket support with fallback to comet-style AJAX communication. Union is a platform for creating connected applications, such as online multiplayer games.
http://www.unionplatform.com

Is there a Telnet library for JavaScript?

We have a network camera. It has an HTTP server to provides the current image. There is also a Telnet interface for controlling the camera (i.e. trigger, focus, etc.). I would like to add an HTML page to the camera that would provide a simple interface (we already have client software we write). I can "GET" the image and display that, but I would also like to have controls that use the Telnet interface to control the camera. So a button might have JavaScript code behind it that connects to the camera via Telnet (logs in) and issues the command to trigger the camera.
I know that JavaScript/browsers support connecting to the same host via XMLHttpRequest. In this case I would be looking to open a socket on port 23 and send text. I also know that I can do this through Flash, Java, or some other technology, but I would prefer to use JavaScript only. If that is possible.
Thomaschaaf is correct, while HTML5 introduces websockets you'll find they still require special server support as they post HTTP style information upon opening the socket:
JS/HTML5 WebSocket: Connect without HTTP call
The best way, currently, to have true sockets is to either
use a flash or Java component on the webpage that does the actual socket work.
use a proxy server with websockets that can handle the additional protocol overhead of websockets and connect to the real tcp/ip port with plain sockets.
The jsterm example Matt linked does the latter, and if your webcans are behind a firewall it will not work in your situation without also implementing another server.
There are libraries that implement the first method, two are linked here for convenience, many others can be found using a search engine:
http://stephengware.com/proj/javasocketbridge/ (Java)
http://matthaynes.net/blog/2008/07/17/socketbridge-flash-javascript-socket-bridge/ (Flash)
jsTerm is an HTML5 implementation of a Telnet client.
You'll need a browser that supports HTML5 WebSockets. WebSockets is the only method of doing non-HTTP requests with pure JavaScript.
Currently there is no way to do socket connections with JavaScript only.
But what you are searching for is a socket connection ;)
https://developer.mozilla.org/en/XML_Extras
If I interpret the question liberally as "is there a remote connectivity library for Javascript", then the answer is yes (quoting from https://xtermjs.org/):
A web based SSH2 client using xterm.js, socket.io, and ssh2: https://github.com/billchurch/WebSSH2
HTML5 Based SSHv2 Web Client with E2E encryption utilising xterm.js, SJCL & websockets: https://github.com/stuicey/SSHy
I've tried WebSSH2 with node.js briefly, it worked for me - I managed to connect to a Linux-based server with it.
(I know this probably doesn't help the OP but this is a 7-year old question anyway. Maybe it helps others who are needing an answer to a similar problem.)

Categories