Install Node. js and ZeroMQ on javastuserver12.10

Source: Internet
Author: User
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

  1. //
  2. // 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

  1. //
  2. // Hello World server
  3. // Binds REP socket to tcp: // *: 5555
  4. // Expects "Hello" from client, replies with "World"
  5. //
  6. # Include
  7. # Include
  8. # Include
  9. # Include
  10. IntMain (Void)
  11. {
  12. IntRet;
  13. CharBuf [5] = "world ";
  14. Buf [5] = 0;
  15. Void* Context = zmq_ctx_new ();
  16. // Socket to talk to clients
  17. Void* Responder = zmq_socket (context, ZMQ_REP );
  18. Ret = zmq_bind (responder, "tcp: // *: 5555 ");
  19. If(Ret = 0 ){
  20. Printf ("zmq_bind success \ n ");
  21. }Else{
  22. Printf ("zmq_bind error = % d: % s \ n", ret, strerror (errno ));
  23. Exit (ret );
  24. }
  25. While(1 = 1 ){
  26. // Wait for next request from client
  27. Printf ("wait for clients... \ n ");
  28. Zmq_msg_t request;
  29. Zmq_msg_init (& request );
  30. Ret = zmq_msg_recv (& request, responder, 0 );
  31. Printf ("Received = % d \ n", ret );
  32. Zmq_msg_close (& request );
  33. // Do some 'work'
  34. Sleep (1 );
  35. // Send reply back to client
  36. Zmq_msg_t reply;
  37. Zmq_msg_init_data (& reply, buf, 6, 0, 0 );
  38. Ret = zmq_msg_send (& reply, responder, 0 );
  39. Printf ("zmq_msg_send ret = % d \ n", ret );
  40. Zmq_msg_close (& reply );
  41. }
  42. // We never get here but if we did, this wocould be how we end
  43. Zmq_close (responder );
  44. Zmq_ctx_destroy (context );
  45. Return0;
  46. }

The following is a compilation command:
$ Gcc mqclient. c-o mqclnt-lzmq
$ Gcc mqserver. c-o mqsrvr-lzmq

Run:
$./Mqsrvr &
$./Mqclnt

End!

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.