nanomsg sockets library for Fortran

A little background:  nanomsg is a sockets library that provides several communication patterns that are designed to be the building blocks for distributed systems.  Built in C, it was created by the lead developer of ZeroMQ, Martin Sustrik.  It is light, powerful, and succinct.

Up until now, sockets-based network communication in Fortran was limited (as far as I know) to using the winsock2 library put together by Intel(?).  Succinctness was not its strong point.  But with the advent of nanomsg and the use of the iso_c_binding intrinsic module standardized by Fortran 2003, I have developed Fortran bindings for nanomsg that will allow for very easy (and succinct!) sockets-based communication:

https://github.com/jshahbazi/nanofort

Included in the nanomsg.f90 file are examples for most of the functions.  I’m confident that there shouldn’t be any problems, but if there are, please let me know by opening an issue on github or leaving a comment here.

One final note: Not only is Fortran 2003 is required for this, but you will also need to compile the nanomsg library and include it in your projects to make this work.

 

Advertisements

4 responses to “nanomsg sockets library for Fortran

  1. Ram September 27, 2014 at 10:28 PM

    Thank you for this bindings library. Could you pls post a full socket example in fortran using these bindings.

  2. Alex M December 22, 2014 at 6:09 AM

    Hi John,

    Thank you so much for putting together the library. I’ve used some of your examples as the basis for a control systems project I’m working on. They’re very helpful. But I’m stuck on implementing the example given in Tim Dysinger’s blog on establishing a pipeline; specifically how to ‘nn_recv” without stipulating the size of the character array prior to it being received. (In your example you fix the size of the array.)

    The nanomsg documents say, “let the buf parameter be a pointer to a void* variable (pointer to pointer) to the receive buffer and set the len parameter to NN_MSG”. Are you able to offer any guidance on how to implement this in Fortran? What might need to modified in your example to achieve this?

    Best,

    Alex.

  3. SOLID May 6, 2016 at 9:49 AM

    I know this is a long time since you have been on here but I hope you can help. I’m having trouble getting this to send data after compiling. I have a reply sever running at 127.0.0.1:5555 which I have tested with a request client application and it works. The tested server and client are using zmq on LabVIEW.

    program hello
    use iso_c_binding
    use nanomsg
    character(len=3) :: command
    integer(c_int) :: socket_num, nbytes, rc, eid1, eid2
    type(c_ptr) :: buffer_ptr
    socket_num = nn_socket (AF_SP, NN_PUB)
    eid1 = nn_bind (socket_num, “ipc:///tmp/test.ipc”)
    eid2 = nn_bind (socket_num, “tcp://127.0.0.1:5555”)
    command = ‘ends’
    buffer_ptr = c_loc(command)
    nbytes = nn_send(socket_num, buffer_ptr, sizeof(command), 0)
    CALL sleep(1)
    !nbytes = nn_recv(socket_num, buffer_ptr, sizeof(command), 0)
    rc = nn_close (socket_num);
    print *, “Hello World!”
    print *, eid1
    print *, eid2
    print *, socket_num
    print *, buffer_ptr
    print *, addr
    end program hello

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s