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?
-
Are you find a WebSockets? http://socket.io/ http://caniuse.com/#feat=websockets – NiLL Nov 14 '12 at 12:50
-
@NiLL the way of socket.io sending message is through a server to a client, dont know if its possible to use socket.io between clients only – nihulus Nov 14 '12 at 13:07
-
possible duplicate of http://stackoverflow.com/questions/1032006/will-html5-allow-web-apps-to-make-peer-to-peer-http-connections – xiaoyi Nov 14 '12 at 14:00
-
I am looking for same kind of question https://stackoverflow.com/questions/53809499/fire-one-website-javascript-function-from-another-without-server-side-langauge?noredirect=1#comment94467614_53809499 – Muhammad Faizan Khan Dec 17 '18 at 06:05
5 Answers
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.

- 9,379
- 4
- 40
- 52
-
thanks for replying! So if my server is overloaded with clients therefor my first thought was sending message between clients only, seems this is not a go, would u suggest any other solution or work around? – nihulus Nov 14 '12 at 14:10
-
Move as much logic as possible out of the server / split it up into multiple components that can run on multiple machines. node.js should be able to handle [many many](http://stackoverflow.com/questions/10161796/how-many-users-nodejs-socket-io-can-support) socket.io clients at the same time, do you have more? – rdrey Nov 14 '12 at 14:18
-
1For people reading this after 2016, SPDY is now deprecated. Google removed SPDY support in Google Chrome 51. Mozilla removed it in Firefox 50.[8] Apple has deprecated the technology in macOS 10.14.4 and iOS 12.2. – svenema May 23 '20 at 11:11
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...)

- 1,835
- 17
- 15
-
how come it does nothing with server? the server has to start a client, and when a 2nd client is started, there should be a way of sending message between the two clients only – nihulus Nov 14 '12 at 13:09
-
Sorry, I didnt ment initial chat does not require server, but chat between two clients later(if you do not want to go through server) does not. Maybe I wasnt clear enough. Anyway if you are able to use flash/flex then go out with RTMFP. Chat roulette is made that way – Igor Nov 14 '12 at 13:11
-
ty for cleaning up, so what u suggest is about real time IO if I didnt missunderstand? Then do you know about nowjs https://github.com/Flotype/now ? Maybe its a solution too? – nihulus Nov 14 '12 at 13:20
-
That doesnt look to me like valid pear to pear socket library, it looks like some kind of framework based on express and I suppose it is meant for rapid web application developing. Communication clinet-server and client-client is very different because, for start, client always knows server IP address – Igor Nov 14 '12 at 13:24
If you just don't want to write your own server you can use:
Use AJAX calls to communicate between peers.

- 4,683
- 4
- 45
- 81