5

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?

xiaoyi
  • 6,641
  • 1
  • 34
  • 51
nihulus
  • 1,475
  • 4
  • 24
  • 46
  • 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 Answers5

5

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.

rdrey
  • 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
  • 1
    For 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
2

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.

Kostanos
  • 9,615
  • 4
  • 51
  • 65
1

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...)

Igor
  • 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
0

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.

Community
  • 1
  • 1
NiLL
  • 13,645
  • 14
  • 46
  • 59
0

If you just don't want to write your own server you can use:

https://httprelay.io

Use AJAX calls to communicate between peers.

Jonas
  • 4,683
  • 4
  • 45
  • 81