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