菜单
  

    it has already been routed. Other ways to get the identifier would be to send the pathname segment from the client side or to initially serve it using a res.local (variables scoped to the request/response cycle) and exposing as a global variable on the client side. Using socket.handshake is quite long but in this case it is a nice way to avoid sending from  the client side.
        With the identifier stored in a variable called room, we can now use socket.join(room); to join a Socket.IO room with the same name as the ID. These rooms are basically a way to send the right messages to the right people, only members of the room will get the messages for that particular room. To check for messages or when the user leaves the room, we use event handlers on socket. Every communication over Socket.IO is classed as a message, not to be confused with the messages that are written in the chatroom.                 Sending messages is called emitting. For messages in the chatroom to be sent to each other, we first emit the message on the client side to the server, which then sends it to the other clients connected to the room.
    To emit a message to the room from the server we use io.sockets.in(room).emit(key, value);. For a chatroom message we use the string 'message' as the key and the data is passed through as the value from a data parameter on the event listener. For leaving a room, the key is 'leave'. And that’s it for the server in terms of a basic chatroom, you can see how brief the code is in Listing 7-1. All we need to do now is for the event handlers on the client-side to emit the messages when sent so that, using the power of Socket.IO rooms and the code we have just written, it will automatically send the messages to anybody in the same
    room— in real time! There is no AJAX or long polling to worry about, Socket.IO uses the best method available (most modern browsers use Web Sockets but others fall back to the appropriate method). The lack of using AJAX is one of the biggest factors in my choice to not use jQuery or any similar libraries for this chapter.
    B.原文的翻译实时协作
    在书中到目前为止,我们所写的代码已经被客户端,虽然客户端JavaScript是非常强大的,现在常常需要有一个服务器,数据可以在线存储,逻辑从客户端保持敏感,或者这样用户可以在网上彼此交互。你可能熟悉其他服务器端语言,如PHP和Ruby(甚至可能Perl !),但节点的优势之一:js是你写服务器端在JavaScript代码,所以应该很容易因为你有客户端JS的经验去做一个聊天室。论文网
    在这一章里,我们使用节点。js和套接字。IO创建一个实时聊天室web应用程序,允许多个用户彼此交谈。我指导你通过设置节点。js在本地机器上,因为最常用的服务器(共享主机)不支持节点。js,但是请注意,一些如Heroku和Amazon Web服务服务有免费的层。安装node . js显然使用节点写任何东西。js,你需要安装它。有很多方法可以安装它。你可以使用包管理器,如apt-get百胜,或者自制程序(取决于您使用的操作系统)但这些并不总是最新的。在节点上。js的网站,www.nodejs.org,您可以下载最新的版本可执行的二进制文件或从源代码构建它。或者,您可以使用节点版本经理(nvm)是特别有用如果你正在与许多并非所有的代码库使用最新的版本。节点有一个内置的包管理器称为npm,使用处理依赖关系文件包。json,而不是安装表达和套接字。IO自己,你只是把它放在该文件。当你准备安装包,运行npm package.json安装文件夹内。与传统的JavaScript,节点。js有一个模块系统,允许您在运行时加载JavaScript文件。每个模块都定义在一个文件中,通过一个模块输出变量和函数。出口对象。在另一个文件,您可以使用“要求”函数加载模块和模块。出口的内容。有三个不同的方法来加载模块。
  1. 上一篇:ASP英文参考文献翻译
  2. 下一篇:学生信息管理系统英文文献和中文翻译
  1. 汽车内燃机连杆载荷和应...

  2. 机械手系统英文文献和中文翻译

  3. 固体氧化物燃料电池英文文献和中文翻译

  4. 船舶运动仿真系统英文文献和中文翻译

  5. 新能源空调系统设计英文文献和中文翻译

  6. 正交试验回归法和响应曲...

  7. 机械设计制造及其自动化英文文献和中文翻译

  8. 巴金《激流三部曲》高觉新的悲剧命运

  9. 上市公司股权结构对经营绩效的影响研究

  10. 现代简约美式风格在室内家装中的运用

  11. 高警觉工作人群的元情绪...

  12. 中国传统元素在游戏角色...

  13. C++最短路径算法研究和程序设计

  14. NFC协议物理层的软件实现+文献综述

  15. 浅析中国古代宗法制度

  16. 江苏省某高中学生体质现状的调查研究

  17. g-C3N4光催化剂的制备和光催化性能研究

  

About

优尔论文网手机版...

主页:http://www.youerw.com

关闭返回