Simple chat function implementation
Implementation function: users need to go online first, then can send content in the chat room, can also send emoticons. Multiple people can chat at the same time. Use HTTP protocol, with WS (WebSokcet) long link protocol to complete
Introduce modules such as HTTP and WS into node.js. The first step is to make the front and back ends establish a connection, using the new WebSocket () method to connect the front and back ends. The second step is for the back end to receive the link, using socket.on(‘connection’, function (ws) {} where ws is the ws object created by the front end using new. The third step is websocket. onopen after the front end receives and the back end opens the server. The fourth step is that the front end sends the requested data to the back end. The fifth step is that the back end makes data processing after receiving the data. Ws. on(‘message’,function(data){}
After complete style layout, write online function, determine on-line box content can’t be empty, when the server opens, we will we get id value, together an object, there are two type and value attributes, and then send the object to the back end, back end after receiving the book, to make processing, whether the type of id, then the return value. The sending caution function is similar to the online function, which is also to splice an object with attributes and content and pass it to the back end, which makes processing, saves the overall content in an array, and then returns it to the front end, which takes the data processed by the back end and renders the display ID and content.
After finish the work in front of it to send here, first will need expression, is a kind of static, is a kind of dynamic ready, then add all the expression to the expression of panel, write the mouse move into and out of the event, the expression in the mouse after can move, then expression splicing display in a fixed position.