Code Monkey home page Code Monkey logo

ffi-rxs's Introduction

About ffi-rxs

This gem wraps the Crossroads I/O messaging library (libxs) using the Ruby FFI (foreign function interface). It’s a pure Ruby wrapper so this gem can be loaded and run by any Ruby runtime that supports FFI. That’s all of them: MRI 1.9.x, Rubinius and JRuby.

Crossroads I/O is a fork of ZeroMQ. This gem is a re-working of the ffi-rzmq gem created by Chuck Remes to provide bindings for the libxs library instead of the ZeroMQ libzmq library.

Features/Problems

This gem needs to be tested in the wild. Please kick its tyres and give it a good thrashing. It is inevitable that bugs will be discovered, so please open issues for them here or fork this project, fix them, and send me a pull request.

The ‘ffi’ gem has dropped support for MRI 1.8.×. Since this project relies on that gem to load and run this code, then this project does not support MRI 1.8.×. I recommend JRuby for the best performance and stability.

Requirements

  • Crossroads I/O version 1.0.0 or later.
  • ffi (>= 1.0.0)

The libxs library must be installed on your system in a well-known location like ‘/usr/local/lib’.

Do not run this gem under MRI with an old ‘ffi’ gem. It will not work as expected.

NOTE
The master GitHub repository contains a copy of the libxs library in the ‘ext’ directory. This is so that the Travis CI continuous integration build platform can be used. The .gemspec file excludes the ‘ext’ directory from the gem build.

If you want to build a gem using a version of libxs other than your current system version, then you can include the library in the ‘ext’ directory. Do not forget to change the .gemspec file so that it does not exclude the library from the gem build.

Installation

A full gem has been released to Rubygems.org as of release 1.0.0. Make sure the Crossroads I/O library is already installed on your system.

  • gem install ffi-rxs # should grab the latest release

To build from git master:

  • git clone git://github.com/celldee/ffi-rxs
  • cd ffi-rxs
  • gem build ffi-rxs.gemspec
  • gem install ffi-rxs-*.gem

NOTE for Windows users!
In order for this gem to find the libxs.dll, it must be on the Windows PATH. Google for “modify windows path” for instructions on how to do that if you are unfamiliar with that activity.

Examples

Using Request (REQ) socket -

require 'ffi-rxs'

ctx = XS::Context.create()
socket = ctx.socket(XS::REQ)
socket.connect("tcp://127.0.0.1:5000")
 
(1..10).each do |i|
  msg = "msg #{i.to_s}"
  socket.send_string(msg)
  puts "Sending: " + msg
  socket.recv_string(msg_in = '')
  puts "Received: " + msg_in
end

Using Reply (REP) socket -

require 'ffi-rxs'

ctx = XS::Context.create()
socket = ctx.socket(XS::REP)
socket.bind("tcp://127.0.0.1:5000")
 
while true do
  socket.recv_string(msg = '')
  puts "Got: " + msg
  socket.send_string(msg)
end

The above examples and additional ones are available in the repository examples folder.

Links

License

This project is licensed under the MIT license. Please see the LICENSE file in the repository.

ffi-rxs's People

Contributors

celldee avatar schmurfy avatar

Stargazers

 avatar

Watchers

 avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.