Experience of web chat room development

Source: Internet
Author: User

Took 5 days to do a web version of the chat room program, the front end using div+css imitation of an interface, the backend using Nodejs write server, using WebSocket protocol to communicate.

During the development process, I looked at some demos because I didn't know websocket very well. Specifically, some understanding of websocket.

The WebSocket protocol is based on the TCP protocol and addresses some of the limitations that the HTTP protocol can send information to the client first. In the past to solve this problem need to use the inquiry mechanism, the client every time to see there is no server-side data sent, this practice is very expensive for the client is the browser performance. The WebSocket protocol solves this problem. WebSocket can send data either from the client or from the server.

var websocketserver = require (' ws '). Server,
chatroom = new Websocketserver ({port:8181});//server-side

var ws = new WebSocket ("ws://192.168.1.3:8181");//Client

WebSocket is based on the event-handling mechanism, when new WebSocket ("ws://192.168.1.3:8181") is in effect, the client is already connected to the server side, and the server side handles the subsequent events through the OnConnection function. The information sent by the client is received through the OnMessage function, and the client receives the data sent by the server via the OnMessage function.

Generally speaking with Nodejs write backstage or is relatively simple, because just began to contact and learn Nodejs, for some nodejs the use of the skills are very short, many times only focus on the implementation of some functions, the overall system architecture and stability is poor, code changes very laborious, In the development of this area I am also a new person, I hope that through continuous learning efforts, work experience to improve themselves.

The following is the project, the code is not uploaded, sorted out, iterative, packaging and so on.

Experience of web chat room development

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.