# Membrane Multimedia Framework: UDP Element
[![CircleCI](https://circleci.com/gh/membraneframework/membrane-element-udp.svg?style=svg)](https://circleci.com/gh/membraneframework/membrane-element-udp)
This package provides elements that can be used to read from and write to UDP sockets.
## Installation
Add the following line to your `deps` in `mix.exs`. Run `mix deps.get`.
```elixir
{:membrane_element_udp, "~> 0.2"}
```
## Usage example
The example below shows 2 pipelines: `UDPDemo.Upload` downloads an example file over HTTP and
```elixir
defmodule UDPDemo.Send do
use Membrane.Pipeline
alias Membrane.Element.{Hackney, UDP}
alias Membrane.Pipeline.Spec
def handle_init(_) do
children = [
source: %Hackney.Source{
location: "https://membraneframework.github.io/static/video-samples/test-video.h264"
},
udp: %UDP.Sink{
destination_address: {127, 0, 0, 1},
destination_port_no: 5001,
local_address: {127, 0, 0, 1}
}
]
links = %{
{:source, :output} => {:udp, :input}
}
spec = %Spec{children: children, links: links}
{{:ok, spec: spec}, %{}}
end
end
defmodule UDPDemo.Receive do
use Membrane.Pipeline
alias Membrane.Element.{File, UDP}
alias Membrane.Pipeline.Spec
def handle_init(_) do
children = [
udp: %UDP.Source{
local_address: {127, 0, 0, 1},
local_port_no: 5001
},
sink: %File.Sink{
location: "/tmp/udp-down.h264"
}
]
links = %{
{:udp, :output} => {:sink, :input}
}
spec = %Spec{children: children, links: links}
{{:ok, spec: spec}, %{}}
end
end
alias Membrane.Testing.Pipeline
import Membrane.Testing.Assertions
{:ok, sender} = Pipeline.start_link(%Pipeline.Options{module: UDPDemo.Send})
{:ok, recv} = Pipeline.start_link(%Pipeline.Options{module: UDPDemo.Receive})
:ok = Pipeline.play(recv)
assert_pipeline_playback_changed(recv, :prepared, :playing)
:ok = Pipeline.play(sender)
assert_end_of_stream(sender, :udp, :input, 5000)
:ok = Pipeline.stop_and_terminate(sender)
assert_pipeline_playback_changed(sender, :prepared, :stopped)
:ok = Pipeline.stop_and_terminate(recv)
```
## Copyright and License
Copyright 2019, [Software Mansion](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane)
[![Software Mansion](https://membraneframework.github.io/static/logo/swm_logo_readme.png)](https://swmansion.com/?utm_source=git&utm_medium=readme&utm_campaign=membrane)
Licensed under the [Apache License, Version 2.0](LICENSE)