Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Nanomsg library for Rust

License

NotificationsYou must be signed in to change notification settings

thehydroimpulse/nanomsg.rs

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Cargo 0.7.2MIT LicenseBuild StatusBuild status

Documentation

Nanomsg is a modern messaging library that is the successor to ZeroMQ, written in C by Martin Sustrik and colleagues. The nanomsg library is licensed under MIT/X11 license. "nanomsg" is a trademark of 250bpm s.r.o.

Requirements

  • Nanomsg 1.1.4

Installing nanomsg:

make deps

Installation

[dependencies]nanomsg ="0.7.2"

Simply import the crate to use it:

use nanomsg;

Creating a Socket

The basis of Nanomsg is aSocket. Each socket can be of a certain type. The type of a socket defines it's behaviour and limitations (such as only being able to send and not receive).

use nanomsg::{Socket,Protocol,Error};/// Creating a new `Pull` socket type. Pull sockets can only receive messages/// from a `Push` socket type.fncreate_socket() ->Result<(),Error>{letmut socket =Socket::new(Protocol::Pull)?;Ok(())}

Now, each socket that is created can be bound tomultiple endpoints. Each binding can return an error, sowe'll take advantage of the? (try) operator.

use nanomsg::{Socket,Protocol,Error};/// Creating a new `Pull` socket type. Pull sockets can only receive messages/// from a `Push` socket type.fncreate_socket() ->Result<(),Error>{letmut socket =Socket::new(Protocol::Pull)?;// Create a new endpoint bound to the following protocol string. This returns// a new `Endpoint` that lives at-most the lifetime of the original socket.letmut endpoint = socket.bind("ipc:///tmp/pipeline.ipc")?;Ok(())}

The socket is ready to be used now!

Because this is aPull socket, we'll implement reading any messages we receive.

// ... After the endpoint we created, we'll start reading some data.letmut msg =String::new();loop{    socket.read_to_string(&mut msg)?;println!("We got a message: {}",&*msg);    msg.clear();}// ...

That's awesome! But... we have no packets being sent to the socket, so we'll read nothing. To fix this, let's implement the accompanying pairPush socket.

use nanomsg::{Socket,Protocol,Error};fnpusher() ->Result<(),Error>{letmut socket =Socket::new(Protocol::Push)?;letmut endpoint = socket.connect("ipc:///tmp/pipeline.ipc")?;    socket.write(b"message in a bottle");    endpoint.shutdown();Ok(())}

Contributors

(In arbitrary order):

License

The MIT License (MIT)

Permission is hereby granted, free of charge, to any person obtaining a copyof this software and associated documentation files (the "Software"), to dealin the Software without restriction, including without limitation the rightsto use, copy, modify, merge, publish, distribute, sublicense, and/or sellcopies of the Software, and to permit persons to whom the Software isfurnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included inall copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS ORIMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THEAUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHERLIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS INTHE SOFTWARE.

About

Nanomsg library for Rust

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors26

Languages


[8]ページ先頭

©2009-2025 Movatter.jp