mirror of
https://github.com/nnuuvv/mug.git
synced 2025-08-29 01:26:14 +02:00
No description
.github/workflows | ||
src | ||
test | ||
.gitignore | ||
CHANGELOG.md | ||
gleam.toml | ||
manifest.toml | ||
README.md |
mug 🍺
A TCP client for Gleam!
gleam add mug
import mug
pub fn main() {
// Form a connection to a TCP server
let assert Ok(socket) =
mug.new("erlang-the-movie.example.com", port: 12345)
|> mug.timeout(milliseconds: 500)
|> mug.connect()
// Send a packet to the server
let assert Ok(Nil) = mug.send(socket, <<"Hello, Joe!\n":utf8>>)
// Receive a packet back
let assert Ok(packet) = mug.receive(socket, timeout_milliseconds: 100)
packet
// -> <<"Hello, Mike!":utf8>>
}
It also includes support for receiving packages as Erlang messages, enabling TCP sockets to be used within OTP actors.
Documentation can be found at https://hexdocs.pm/mug.