dtvfshi5248 2013-09-05 13:39
浏览 47
已采纳

用PHP,Jquery聊天应用程序

I want to make a chat application with php & jquery. But jquery script visible to client side and another problem is every time need to update chat display panel by calling interval methods. So my question is, is there any other way to develop a chat app like gmail chat app. Becouze gmail chat is show presence. When user went to offline automatically shows offline status. and when user entered text into chat box, instantly shows in chat display. so i wanna make to like that application.

Please guide me....

Thanking you,

  • 写回答

4条回答 默认 最新

  • douzhengzuo7283 2013-09-05 15:02
    关注

    You can do this with WebSockets. There are some cool WebSockets tools out there like:

    Using WebSockets you can append received messages to the chat log instead of updating the whole thing like it seems you are doing.

    In case you choose to (or have to) keep requesting new messages to the server, since not all hosting providers will allow WebSockets, here are some tips that you may find useful to improve your chat app:

    1. Store the last received message id on client-side, so that when you request new messages to the server you can send it this id and it will only send you messages you didn't receive yet, thus avoiding unnecessary traffic.

    2. On the server side, record the last time a client requested new messages, so that you can define a timeout in order to detect user disconnection.

    3. To avoid overloading your server or client with more requests than it can handle, take into consideration the time took by the server to answer your last request when you define the interval for the next request, like this:

      1. Client requests messages
      2. Server replies in 100ms
      3. Client waits 100ms before requesting again
      4. Server replies in 200ms
      5. Client waits 200ms before requesting again
      6. ...
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(3条)

报告相同问题?

悬赏问题

  • ¥15 微信会员卡接入微信支付商户号收款
  • ¥15 如何获取烟草零售终端数据
  • ¥15 数学建模招标中位数问题
  • ¥15 phython路径名过长报错 不知道什么问题
  • ¥15 深度学习中模型转换该怎么实现
  • ¥15 HLs设计手写数字识别程序编译通不过
  • ¥15 Stata外部命令安装问题求帮助!
  • ¥15 从键盘随机输入A-H中的一串字符串,用七段数码管方法进行绘制。提交代码及运行截图。
  • ¥15 TYPCE母转母,插入认方向
  • ¥15 如何用python向钉钉机器人发送可以放大的图片?