Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/lpil/mug
🍺 A TCP client for Gleam!
https://github.com/lpil/mug
Last synced: 21 days ago
JSON representation
🍺 A TCP client for Gleam!
- Host: GitHub
- URL: https://github.com/lpil/mug
- Owner: lpil
- Created: 2023-10-08T15:15:47.000Z (about 1 year ago)
- Default Branch: main
- Last Pushed: 2024-02-29T12:03:28.000Z (10 months ago)
- Last Synced: 2024-05-01T23:05:07.470Z (7 months ago)
- Language: Gleam
- Homepage:
- Size: 17.6 KB
- Stars: 13
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Changelog: CHANGELOG.md
Awesome Lists containing this project
- awesome-gleam - mug - [📚](https://hexdocs.pm/mug/) - A TCP client for Gleam! (Packages / Networking)
README
# mug 🍺
[![Package Version](https://img.shields.io/hexpm/v/mug)](https://hex.pm/packages/mug)
[![Hex Docs](https://img.shields.io/badge/hex-docs-ffaff3)](https://hexdocs.pm/mug/)A TCP client for Gleam!
```sh
gleam add mug
``````gleam
import mugpub 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 .