I know there is an implementation of VNC using WebSockets (http://novnc.com) but that still requires a server. I am looking to create a simple client-side JavaScript only (no Flash) connection to a port running SSH. I am guessing WebSockets is the only way to go since it does TCP. Any example code? Any other way?
Sorry, given your constraints (client-side Javascript only), there is no way to connect to a plain old SSH server.
WebSockets is not plain TCP. It's a framed protocol with a HTTP-like handshake between the client and server that includes origin policy.
Flash can make plain TCP connections, but it also has origin policy enforcement. The way it does this is by making a connection to the same server on port 843 and asking for a special XML file that contains the origin policy.
If you are willing to relax your constraints slightly such that you are willing to run a generic WebSockets to TCP proxy either on a server (any server) or on the client then you can do what you are wanting to do. noVNC includes a C and python WebSockets to TCP proxy: http://github.com/kanaka/noVNC/tree/master/utils/.
Other info you might find useful:
Current WebSocket draft: https://datatracker.ietf.org/doc/html/draft-hixie-thewebsocketprotocol-76
Simple (insecure) way of running a flash policy server (Linux/UNIX with socat) is described here: http://github.com/kanaka/noVNC/blob/master/docs/flash_policy.txt
More info about the flash policy file: http://code.google.com/p/doctype/wiki/ArticleFlashSecurity
You can take a look at serfish. It's a solution to access a SSH server. But if you're hosting your web application on the same server as your ssh, there are other solutions such as shell in a box.
For those still searching, paramikojs could be the answer.
I'm currently having a similar issue:I need a SSH JS client-side implementation, and I need it to be BSD licensed. Alas paramikojs seems to be GPL licensed.
It's definitely possible using a Linux emulator with full network support like the great OpenRISC emulator jor1k.
Note that I've created browser-tools.net, a collection of in-browser tools from number of different projects.
Yes you can
Install SSH server on your server
Write a server side program (could be in PHP) that uses SSH
client in the background
Redirect messages between the SSH client (that probably has been residing in the same server as SSH server) and the JavaScript program in the web browser other side of the internet.
That server side program acts like a postman only and the java script program in the browser is just another postman between the user and server program.
(SSH server)<->(SSH client)<->(PHP e.g)<->(JavaScript)
Also don't forget that in the JavaScript program could have use Ajax for better mechanism. Also SSH client might be not completely and absolutely necessary because that PHP server side program could directly connect to SSH server
Related
I am currently working on a Chromebook (it's the only thing available to me at the time) which is managed and does not have the ability to install Chrome Extensions (such as https://chrome.google.com/webstore/detail/secure-shell/iodihamcpbpeioajjeobimgagajmlibd?hl=en) or enable Linux Beta. Is there a website that will allow me to make SSH connections purely client side so that I can connect to a LAN server, or a Vanilla JS library that I could use to write my own?
The APIs provided by browsers allow network connections to be made through a very limited set of protocols (such as HTTP and WebSockets). They don't support SSH or the raw sockets needed to write an SSH library from scratch.
The only way to do something like this would be to run a server which converted SSH into something else (e.g. with the server establishing an SSH connection and then relaying the data to and from it over a WebSocket).
Is it possible to create a javascript program that connect to a simple C# server using a simple socket and not a WebSocket.
can you help me with a sample.
There is no standard way to make a TCP connection from Javascript code running in a web browser. (See the answer by #Johannes Hahn)
To communicate between your client and server, consider Microsoft's SignalR library. It is designed to allow a Javascript program, running in the browser, to communicate with a C# server. SignalR will use websockets; however, it will continue to work if websockets are not available by falling back to other transports. You can also specify transports, if you need to prevent it from attempting to use websockets.
SignalR connection starts as HTTP, and is then promoted to a WebSocket connection if it is available. WebSocket is the ideal transport for SignalR, since it makes the most efficient use of server memory, has the lowest latency, and has the most underlying features (such as full duplex communication between client and server), but it also has the most stringent requirements: WebSocket requires the server to be using Windows Server 2012 or Windows 8, and .NET Framework 4.5. If these requirements are not met, SignalR will attempt to use other transports to make its connections.
Also, be aware that if your Javascript is not running in a web browser, you can make regular network connections. For example, a Javascript application running on Node.js.
It seems that at least Firefox is supposed to know about socket, see https://developer.mozilla.org/en-US/docs/Web/API/TCP_Socket_API. But (taken from the same source) TCP or UDP sockets are not part of any standard and therefore likely either unsupported or completely different in other browsers.
In principle no. For security reasons browsers only allow a limited set of protocols. Chrome has a socket API, but that is not standard - https://developer.chrome.com/apps/sockets_tcp. There are solutions which use a WebSocket connection to a server which then establishes a TCP socket connection, e.g. https://github.com/kanaka/websockify, http://artemyankov.com/tcp-client-for-browsers/, so if you can't add WebSocket directly to the server you may want to check these out.
I have been working with node.js for a while, now when I'm looking deeper into it, for a chat aplication instead of sending message as client - server - client, there must be some possible ways for direct client to client message sending?
Browsers tend to communicate with servers via HTTP. Some implement other protocols, like websockets & SPDY, but again, these are mostly client-server protocols.
Some plug-ins (like Flash & Java) can open ports and communicate client-client. (AFAIK, haven't actually used them.)
Chrome is the only browser I'm aware of that can (soon) open TCP and UDP sockets from Javascript and do direct client-client communication. At the moment normal web apps can't do this, your app needs to be run as a "Chrome Packaged App", with a special manifest file.
Here are the docs, a blog post describing the feature and a browserify module that can behave like the net node.js module in the browser.
EDIT: This should probably not be tagged as [node.js] since you're trying to run in browsers (not in your node vm), this is a Javascript / Browser question.
This is maybe out of date question, but take a look on PeerJS.
It requires server only as a connection manager (broker). But all communication is done between clients directly.
This does not have anything with server. If you need something like that and if clients are flash you can use RTMFP . For JS i google this library which is js bridge for RTMFP, I dont know how it works. At the end you can write you own library to chat beetween clients but this is much harder(IP addresses are behind NAT, etc...)
I think answer for your question is here
PS Also exist open-source in-browser server which written using JS, but I didn't google it quickly. If you find it, please notify me.
If you just don't want to write your own server you can use:
https://httprelay.io
Use AJAX calls to communicate between peers.
Is it possible to send directly message from JavaScript in client browser to 0mq?
If not in JavaScript, then I should use Flash or setup some http proxy server?
0mq is not meant for Internet facing ports. There is a project called nullmq which does what you want though by translating from web protocols to zmq behind the firewall, while retaining zeromq like api on the browser.
I suspect it would be easiest to have your client browser make an XMLHttpRequest() to your web application and then have your web application talk to your 0MQ infrastructure.
There is a javascript/flash binding for 0MQ, but I've never worked with it myself so I can't comment on stability or anything.
If you tell us more about what you're trying to accomplish we might be able to suggest viable alternatives.
You can use websockets on the client-side if you want a persistent connection and use a websocket server like tornado or socket.io to relay the messages to zmq and back.
I mean pure javascript client that uses HTML5 sockets and doesn't need to be installed, just open single js file in browser. Is it possible to write such client at all?
No.
JavaScript in the browser does not have raw TCP/IP socket support.
It would be possible to create an ssh client using some server-side technology to proxy the connection, and then do the client using JS. But of course for this you would require a server (like node or whatever)
You couldn't do it directly with Web Sockets, as they're (very deliberately) not a general raw socket capability. You would have to have a server-side proxy to forward keystrokes to the target ssh server.
Existing JS SSH implementations (WebShell, AnyTerm) are using XMLHttpRequest to transport data from the client to the proxy server. You could in theory improve their responsiveness by altering them to use WebSocket instead where available, but it's not really widespread yet. Given the number of incompatible changes that have already happened to the specification over its life, many are likely to be waiting for the ‘final’ version.