Project needs, so I learned how to use node. js + socket. io to implement the private chat function. After busy working for a long time, I finally figured it out. The basic principle is that when the server receives
When a socket connects to the request, each socket will establish a socket, and the connected socket is not expressed, so each socket can only send i
This article will introduce the net module of node. js by developing a simple chat room.
I. The first version only sends information to the client
First, implement a simple version with the following code:
var net=require('net');var chatServer=net.createServer();chatServer.on('connection',function(client){ client.write('hi!\n'); client.write('bye!\n')
. shift (). callback ([]);}},3000 );};
The channel defines two variables, two methods, and a setInterval function that is executed every 3 seconds.First, let's look at the query method,The query method receives two parameters:Since: record a timeCallback: The anonymous function passed in when the channel. query method is called. (In JS, the function can be called directly after the parameter is passed and received. I don't want to make up the course s
Nodejs is a simple chat server.
The implementation code is as follows:
Var net = require ('net'); var chatServer = net. createServer (), clientList = []; chatServer. on ("connection", function (client) {client. name = client. remoteAddress + ":" + client. remotePort; client. write ("Hi! "+ Client. name + "\ n"); clientList. push (client); client. on ("data", function (data) {// send data to the client broadcast (data, client); // clientList [I]. write
This article mainly introduces what is Node. js? What are the advantages of Node. js ?, To try to explain what Node is. js, this article will briefly introduce some background information: the problem to be solved, how it works, h
This article mainly introduces a simple node. js server example. This article implements a simple helloworld example and shows how to run this server, for more information, see the following example: hello world.
It seems that the first section of each language tutorial will talk about this, and we are no exception.
First, create a project directory, which can be defined by yourself. In this case, the d
This article mainly introduces several important knowledge points of node. js: The Role of node. js, callback, synchronous and asynchronous code, event loop 1, and the role of node. js,
The meaning of I/O. Move the mouse to see t
Getting started with Node. js development-notepad ++ for Node. js and node. jsnotepad
For Node. js development, IDE,WebstormIt is the best option, but it is charged (free for 30 days )
based on Websocet simple chat room (Nodejs + node-websocket-server)3 People collection This article, collection of this article published 24 days ago, there have been
135Times read a total
2A comment
3People to collect this article
Recently in the study of HTML5 related things, see WebSocket is a very powerful technology, so a small try, made a simple chat room.
About the difference between node. js and JavaScript, you know? Do you know about the similarities between node. js and JavaScript? If you do not know, then don't come to see this article, you are still waiting for what, see now
First, let's look at the comparison between JS
This article mainly introduces four js key points that Node. JS developers must understand. Node. js is a server-oriented framework based on Chrome's powerful V8JS engine. Although it is compiled by C ++, it and its applications run on J
Quick understanding of Node. js environment configuration in the Window of node. js, Node. jsnodejs
In the window, I also tried it. The installation was complete and the test passed!
1. Download node
Download
. underscore (Lodash, lazy) – the most popular JavaScript ToolPak, a package for node. JS, and two peers who take a slightly different approach to achieving better performance. forever– is probably the most popular tool for ensuring that the node script continues to run. There are a lot of good modules, not listed here (I hope no offense to the list). where
The fourth chapter recommends 3 hours of study time 10 chaptersHow to learn: read it in detail and implement the relevant code manuallyLearning Goals : This tutorial will teach you to install node, build servers, Express, MySQL, MongoDB, write background business logic, write interfaces, and finally complete a complete project backstage, a total of 10 days is expected.node. js Event mechanismnode.
-blocking I/O modules with JavaScript is a good choice. If you plan to write an AJAX single page application (such as Gmail), Node. js is very suitable. Obtain more requests in a very short response time, share data between the client and the server, and perform a lot of processing for modern Web applications on the client, Node.
has its weakness, mainly manifested in three aspects: failure to use multi-core CPU; error may cause the entire application to exit, and the robustness of the application is worthy of further study; A large amount of computing will occupy the CPU and thus cannot continue to call asynchronous I/O.
To solve the above problem, Node adopts the same idea as HTML5 Web Workers and uses child_process to solve the problem of large computing workload in a sing
efficient development, ease of use, and other features to simplify the process of starting functions related to servers and servers.Total. js-a modern Node. js framework for Network Application Development
Although Total. js can be considered as a simple framework, it can still be used as a supplement to the
, and the middleware of the framework isolates these new features from other existing features. In addition, the framework provides efficient development, ease of use, and other features to simplify the process of starting functions related to servers and servers.
Total. js-a modern Node. js framework for network application development
Although Total.
If you're writing the node. JS code, Node-inspector is a must-have option, much better than node. JS's built-in debugger. It's similar to Chrome's JavaScript debugger.To install with NPM:$ npm install -g node-inspectorThen you need to connect to
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.