# Getting Started
```toml
[dependencies]
rustzmq2 = "0.1"
tokio = { version = "1", features = ["full"] }
```
## REQ / REP
```rust
// Server
use std::convert::TryInto;
use rustzmq2::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut rep = rustzmq2::RepSocket::new();
rep.bind("tcp://127.0.0.1:5555").await?;
loop {
let msg: String = rep.recv().await?.try_into()?;
rep.send(format!("{msg} reply").into()).await?;
}
}
```
```rust
// Client
use rustzmq2::prelude::*;
#[tokio::main]
async fn main() -> Result<(), Box<dyn std::error::Error>> {
let mut req = rustzmq2::ReqSocket::new();
req.connect("tcp://127.0.0.1:5555").await?;
req.send("hello".into()).await?;
let reply: String = req.recv().await?.try_into()?;
println!("{reply}");
Ok(())
}
```
## PUB / SUB
```rust
// Publisher
let mut pub_ = rustzmq2::PubSocket::new();
pub_.bind("tcp://127.0.0.1:5556").await?;
pub_.send("weather 22.5C".into()).await?;
```
```rust
// Subscriber
let mut sub = rustzmq2::SubSocket::new();
sub.connect("tcp://127.0.0.1:5556").await?;
sub.subscribe("weather").await?;
let msg: String = sub.recv().await?.try_into()?;
```
## PUSH / PULL
```rust
// Ventilator
let mut push = rustzmq2::PushSocket::new();
push.bind("tcp://127.0.0.1:5557").await?;
push.send("work item".into()).await?;
```
```rust
// Worker
let mut pull = rustzmq2::PullSocket::new();
pull.connect("tcp://127.0.0.1:5557").await?;
let task: String = pull.recv().await?.try_into()?;
```
## Transports
Swap the address scheme:
- `tcp://host:port`
- `ipc:///path/to/socket` — Unix-only, needs the `ipc` feature
- `inproc://name` — same-process only, needs the `inproc` feature
## Further reading
- [examples/](../examples/) — runnable examples for every pattern
- Security (PLAIN, CURVE, ZAP) — see the builder method docs via `cargo doc`
([`curve_client`], [`curve_server`], [`plain_client`], [`plain_server`],
[`zap_domain`]) and [RFC 23](https://rfc.zeromq.org/spec/23/) for the wire
protocol
[`curve_client`]: https://docs.rs/rustzmq2/latest/rustzmq2/struct.SocketBuilder.html#method.curve_client
[`curve_server`]: https://docs.rs/rustzmq2/latest/rustzmq2/struct.SocketBuilder.html#method.curve_server
[`plain_client`]: https://docs.rs/rustzmq2/latest/rustzmq2/struct.SocketBuilder.html#method.plain_client
[`plain_server`]: https://docs.rs/rustzmq2/latest/rustzmq2/struct.SocketBuilder.html#method.plain_server
[`zap_domain`]: https://docs.rs/rustzmq2/latest/rustzmq2/struct.SocketBuilder.html#method.zap_domain
- `cargo doc --open`
- [ZeroMQ guide](https://zguide.zeromq.org/) — pattern concepts (language-agnostic)