Luke
Luke

Reputation: 18983

How can I communicate over TCP sockets from JavaScript?

I'm thinking about how limiting it is for AJAX apps to have to poll for updates, when what would be ideal is for javascript to be able to set up a real two way connection to the server. I'm wondering if there is some method of integrating javascript with a browser plugin that can make a tcp connection so that I could pass data into and out of the browser plugin.

Upvotes: 24

Views: 37776

Answers (4)

Vishal
Vishal

Reputation: 20627

You can use node.js framework's socket.io package which can can be installed via npm (A node package manager).

More detailed usage.

Upvotes: 9

jnnnnn
jnnnnn

Reputation: 4438

WebSockets is designed to solve this problem.

Upvotes: 16

pix0r
pix0r

Reputation: 31290

jSocket and Stream are two options that utilize Flash's built-in XML sockets, though neither appears to be production-ready. I'd lean towards using a Flash-based solution rather than Java, as browser penetration is higher and generally offers a better user experience (load times & stability).

Upvotes: 6

Christian C. Salvadó
Christian C. Salvadó

Reputation: 827862

Here is an implementation with a similar approach:

It uses a Java Applet and bridges its API to JavaScript, interesting...

And here another one:

This one is a wrapper of the Actionscript 3 Socket API, bridged to JavaScript...

Upvotes: 11

Related Questions