dqmg80654 2017-04-19 04:42
浏览 90

如何在浏览器用户之间进行实时交互

I have a web page with four textarea. Suppose page URL is example.com?Id=5

Now what I want to achieve is when two users visit this page. And one of them make change in the content of any text area. Then it should reflect the changes in the window of all other users of same URL. Please give instructions to achieve this.

  • 写回答

2条回答 默认 最新

  • doukuanghuan7582 2017-04-19 04:47
    关注

    Websockets can be a great solution. For instance, you can create a pub/sub design pattern where the two users will subscribe to the server via a websocket for instance . . .

    var ws = new WebSocket('ws://yourdomain.com/ws-route');
    ws.onmessage = function(m) {
    console.log(m); // this is how you will receive your messages
    ws.send('i am acknowledging your message and sending you back mine.');
    }
    

    every send from either users will be read by the server and published back to both users (or the other user depending on your strategy). in this way, you can achieve this effect. for instance, you can hook the on keyup or something on the textarea to ws.send using the value of the textarea. then you can hook the onmessage even to change the value of textarea whenever you receive a new messsage.

    评论

报告相同问题?

悬赏问题

  • ¥15 用windows做服务的同志有吗
  • ¥60 求一个简单的网页(标签-安全|关键词-上传)
  • ¥35 lstm时间序列共享单车预测,loss值优化,参数优化算法
  • ¥15 Python中的request,如何使用ssr节点,通过代理requests网页。本人在泰国,需要用大陆ip才能玩网页游戏,合法合规。
  • ¥100 为什么这个恒流源电路不能恒流?
  • ¥15 有偿求跨组件数据流路径图
  • ¥15 写一个方法checkPerson,入参实体类Person,出参布尔值
  • ¥15 我想咨询一下路面纹理三维点云数据处理的一些问题,上传的坐标文件里是怎么对无序点进行编号的,以及xy坐标在处理的时候是进行整体模型分片处理的吗
  • ¥15 一直显示正在等待HID—ISP
  • ¥15 Python turtle 画图