javascript - Allow two clients interact without server - Stack Overflow

Is it possible to allow two clients interact directly without a server?I am referring to websites, for

Is it possible to allow two clients interact directly without a server?

I am referring to websites, for example is it possible to create a chat between two clients that are on the same website using only javascript on the client-side.

If not, what's the minimum server-side to make a chat work between active clients on a website? (eg: one PHP file and no database) ?

My idea: Storing the conversation would be easily done using localStorage on each client, the problem is how to send some data from client1 to client2 without storing anything (or at most that message) in the database. Also, note that "past" conversations should not visible, so no storage needed for that.

Note that I don't want any nodeJS or websocket solutions, I want something as simple as possible. So, what's the minimum code and files to make a chat between online users?

Is it possible to allow two clients interact directly without a server?

I am referring to websites, for example is it possible to create a chat between two clients that are on the same website using only javascript on the client-side.

If not, what's the minimum server-side to make a chat work between active clients on a website? (eg: one PHP file and no database) ?

My idea: Storing the conversation would be easily done using localStorage on each client, the problem is how to send some data from client1 to client2 without storing anything (or at most that message) in the database. Also, note that "past" conversations should not visible, so no storage needed for that.

Note that I don't want any nodeJS or websocket solutions, I want something as simple as possible. So, what's the minimum code and files to make a chat between online users?

Share edited Mar 21, 2013 at 15:30 XCS asked Mar 21, 2013 at 15:16 XCSXCS 28.2k28 gold badges104 silver badges153 bronze badges 12
  • 1 Yes. Provide each participant with the other participant's phone number? ;-) Seriously though +1 from me as I'm interested in the answers. – Sepster Commented Mar 21, 2013 at 15:19
  • @JamieHutber I guess the OP is asking if it's possible to set up a listener in JavaScript inside the browser (presumably the server would somehow advise each client of the other client's details, then leave it to the clients). Your ment would suggest this is not possible. – Sepster Commented Mar 21, 2013 at 15:20
  • 2 @Cristy this post looks very relevant, although I think the short answer from this is still "no, for now at least, not without resorting to another technology". stackoverflow./questions/7022383/… – Sepster Commented Mar 21, 2013 at 15:24
  • 2 Maybe check out the webRTC project? webrtc – Christophe Commented Mar 21, 2013 at 15:33
  • 1 @Cristy What about offloading the server-side stuff to a 3rd party eg mibbit. et al? (I've not used these so can't ment on their usefulness or appropriateness). – Sepster Commented Mar 21, 2013 at 15:52
 |  Show 7 more ments

3 Answers 3

Reset to default 5

The WebRTC APIs will allow JavaScript to initiate a direct browser-to-browser connection, but a server is still required to serve the page and coordinate session initiation.

The APIs are still rapidly evolving and only available in bleeding-edge browsers, so it's not yet ready for real production use.

However—to be honest—for what you're trying to do, the easiest option is Node and socket.io:

var http=require('http'), express=require('express'), sio = require('socket.io')
    , app=express(), srv = http.createServer(app);

app.use(express.static(__dirname+'/static'));

sio.listen(srv);
srv.listen(80);

...and now you have a working websockets server in 5 lines. Put all your client-side stuff in the static folder and you're good to go.

HTML5 has got a new Web Sockets feature

With this the server intervention is almost nullified..The server and client municate through the new protocols

  • ws - Web Sockets protocol
  • wss - Web Sockets Secure protocol (similar to https)

Live demo

No, It's not possible. If you want a chat box, you have to store the data in the server. And what connects the clients, like display the chat texts and the same things to every client, they e from the server.. So it's not possible like that. Well, even free chat boxes put the data of each sites in their servers.

As for your idea using localStorage, maybe it's possible (But still, using the new WebSocket protocol), but it doesn't work in the time dimension, right? if another user joins, they won't see what has been sent before.

发布者:admin,转转请注明出处:http://www.yc00.com/questions/1742296461a4417220.html

相关推荐

  • javascript - Allow two clients interact without server - Stack Overflow

    Is it possible to allow two clients interact directly without a server?I am referring to websites, for

    17小时前
    20

发表回复

评论列表(0条)

  • 暂无评论

联系我们

400-800-8888

在线咨询: QQ交谈

邮件:admin@example.com

工作时间:周一至周五,9:30-18:30,节假日休息

关注微信