With the help of lori, we finally finished running a websocket service. I have a general understanding of the real faces of the web service under nodejs. Although I have some knowledge and knowledge, it is quite rewarding. The process is summarized as follows: Environment: node version v0.4.12, the websocket-server and antinode code must be downloaded from the Internet (provided by lori). Specifically, it is a client that draws pictures. The effect is that when drawing pictures on a client, other clients connected to the server can
With the help of lori, we finally finished running a websocket service. I have a general understanding of the real faces of the web service under nodejs. Although I have some knowledge, it is quite rewarding. The process is summarized as follows:
Environment: node v0.4.12, which requires websocket-server and antinode
The Code is the example word downloaded from the Internet (provided by lori), specifically a drawing client. The effect is that when a client draws a picture, the other clients connected to the server can see the drawing effect; the second is the chat room. The server sends messages from one of the clients to other clients.
My understanding of antinode: antinode functions are similar to tomcat, apache, and other web servers. After antinode is successfully installed, enter the antinode folder and you can see a setting-sample.json file, which specifies the web Service port and file directory, the content format is as follows:
"Port": 8081,
"Hosts ":{
"Www.linuxidc.com ":{
"Root": "/home/test"
},
"Www.linuxidc.net ":{
"Root": "/home/test"
}
},
"Default_host ":{
"Root": "/mycode/nodejs ",
"Sunny": "/mycode/nodejs/sunny"
}
}
Specifically, port specifies the web service access port; default_host specifies the web service directory. Another file in the antinode folder is server. js, if the setting-sample.json file is configured, you can run node server in linux. to access the deployed web Service on the specified port.
My code is stored under the/mycode/nodejs file, and the rest is to enable the web Service server. For example, the name of the rendering server is draw_server.js, to enable this service, run node draw.server. the drawclient file is draw_net_client.html. You can enter the http: // 192.168.0.101: 8081/draw_net_client.html address in the browser to open the html webpage of the server, then you can test the expected results. You can also enable the client on the server side of the chat room.
One problem I encountered during the re-running process was that I could not access the linux service in the LAN and could only access the service on the linux host. After analysis, I found that it was a problem with the linux firewall, therefore, you need to enable ports required for testing such as 8081 in the firewall of linux. The linux Command is:
/Sbin/iptables-I INPUT-p tcp -- dport 8081-j ACCEPT // This line name is modified iptables information open port 8081
/Etc/rc. d/init. d/iptables save // This line of command saves the modified information
Service iptables restart // restart iptables to make the modification take effect
In this way, I found that using node to run a web service similar to a chat room requires two ports. One is the port needed to deploy the web service file. We can access files in the open web service through this port; the other port is occupied by the Chat Server and used to listen for information sent from the client.