Node. js is a server-side programming framework based on googlev8 + javascript. For cloud computing, it is very appropriate to use Node. js for system management of Web sites. The reason is: 1) It is simple enough. 2) fast enough. 3) small enough. 4) consistency between the front and back ends. Well, the following is the installation procedure: first, ensure that python, gcc, g ++ are installed on the system. If not, install: $ sudoapt-getinstallpython $ sudoapt-get
Node. js is a server-side programming framework based on google v8 + javascript. For cloud computing, it is very appropriate to use Node. js for system management of Web sites. The reason is:
1) It is simple enough.
2) fast enough.
3) small enough.
4) consistency between the front and back ends.
The installation steps are as follows:
First, make sure that python, gcc, and g ++ are installed. If not, install:
$ Sudo apt-get install python
$ Sudo apt-get install build-essential
$ Sudo apt-get install gcc
$ Sudo apt-get install g ++
Download the latest source package: node-v0.8.14.tar.gz
Decompress:
$ Sudo tar-zxf node-v0.8.14.tar.gz
$ Node-v0.8.14 cd
(1) installation by default:
$./Configure
$ Make
$ Sudo make install
(2) Select the directory method for installation:
$./Configure -- prefix =/opt/node
$ Make-j 3 #3 = number of CPU cores + 1
$ Sudo make install
After the installation is complete, run the following command to check the installed version:
$ Node -- version
V0.8.14
Next refer to the following article to start your nodejs programming Journey: http://www.linuxidc.com/Linux/2012-11/73363.htm
Zeromq is a c-based message queue programming framework. Zeromq is useful in many ways and has the following features:
1) It is simple enough.
2) fast enough.
3) small enough.
Below are the installation steps:
Download: zero-3.2.1
Http://www.zeromq.org/
$ Tar-xzf zeromq-3.2.1.tar.gz
$./Configure
$ Make
$ Sudo make install
$ Sudo ldconfig
Write a client and a server for testing:
Mqclient. c
- //
- // Hello World client
- // Connects REQ socket to tcp: // localhost: 5555
- // Sends "Hello" to server, expects "World" back
- //
- # Include
- # Include
- # Include
- # Include
- IntMain (Void)
- {
- Void* Context = zmq_ctx_new ();
- // Socket to talk to server
- Printf ("Connecting to hello world server... \ N ");
- Void* Requester = zmq_socket (context, ZMQ_REQ );
- Zmq_connect (requester, "tcp: // localhost: 5555 ");
- IntRequest_nbr;
- For(Request_nbr = 0; request_nbr! = 10; request_nbr ++ ){
- Zmq_msg_t request;
- Zmq_msg_init_data (& request, "Hello", 6, 0, 0 );
- Printf ("Sending Hello % d... \ N ", request_nbr );
- Zmq_msg_send (& request, requester, 0 );
- Zmq_msg_close (& request );
- Printf ("prepare recv message \ n ");
- Zmq_msg_t reply;
- Zmq_msg_init (& reply );
- If(-1 = zmq_msg_recv (& reply, requester, 0 )){
- Printf ("recv data error. \ n ");
- }
- Printf ("Received World % d \ n", request_nbr );
- Zmq_msg_close (& reply );
- }
- Zmq_close (requester );
- Zmq_ctx_destroy (context );
- Return0;
- }
Mqserver. c
- //
- // Hello World server
- // Binds REP socket to tcp: // *: 5555
- // Expects "Hello" from client, replies with "World"
- //
- # Include
- # Include
- # Include
- # Include
- IntMain (Void)
- {
- IntRet;
- CharBuf [5] = "world ";
- Buf [5] = 0;
- Void* Context = zmq_ctx_new ();
- // Socket to talk to clients
- Void* Responder = zmq_socket (context, ZMQ_REP );
- Ret = zmq_bind (responder, "tcp: // *: 5555 ");
- If(Ret = 0 ){
- Printf ("zmq_bind success \ n ");
- }Else{
- Printf ("zmq_bind error = % d: % s \ n", ret, strerror (errno ));
- Exit (ret );
- }
- While(1 = 1 ){
- // Wait for next request from client
- Printf ("wait for clients... \ n ");
- Zmq_msg_t request;
- Zmq_msg_init (& request );
- Ret = zmq_msg_recv (& request, responder, 0 );
- Printf ("Received = % d \ n", ret );
- Zmq_msg_close (& request );
- // Do some 'work'
- Sleep (1 );
- // Send reply back to client
- Zmq_msg_t reply;
- Zmq_msg_init_data (& reply, buf, 6, 0, 0 );
- Ret = zmq_msg_send (& reply, responder, 0 );
- Printf ("zmq_msg_send ret = % d \ n", ret );
- Zmq_msg_close (& reply );
- }
- // We never get here but if we did, this wocould be how we end
- Zmq_close (responder );
- Zmq_ctx_destroy (context );
- Return0;
- }
The following is a compilation command:
$ Gcc mqclient. c-o mqclnt-lzmq
$ Gcc mqserver. c-o mqsrvr-lzmq
Run:
$./Mqsrvr &
$./Mqclnt
End!