GSMLG.Socket.UDP (GSMLG.Socket v0.1.0)

This module wraps a UDP socket using gen_udp.

options

Options

When creating a socket you can pass a series of options to use for it.

  • :as sets the kind of value returned by recv, either :binary or :list, the default is :binary.
  • :mode can be either :passive or :active, default is :passive
  • :local must be a keyword list
    • :address the local address to use
    • :fd an already opened file descriptor to use
  • :version sets the IP version to use
  • :broadcast enables broadcast sending

examples

Examples

server = GSMLG.Socket.UDP.open!(1337)

{ data, client } = server |> GSMLG.Socket.Datagram.recv!
server |> GSMLG.Socket.Datagram.send! data, client

Link to this section Summary

Functions

Convert UDP options to :inet.setopts compatible arguments.

Create a UDP socket listening on an OS chosen port, use local to know the port it was bound on.

Create a UDP socket listening on the given port or using the given options.

Create a UDP socket listening on the given port and using the given options.

Create a UDP socket listening on an OS chosen port, use local to know the port it was bound on, raising if an error occurs.

Create a UDP socket listening on the given port or using the given options, raising if an error occurs.

Create a UDP socket listening on the given port and using the given options, raising if an error occurs.

Set options of the socket.

Set the process which will receive the messages.

Set the process which will receive the messages, raising if an error occurs.

Link to this section Types

@type t() :: port()

Link to this section Functions

Link to this function

arguments(options)

@spec arguments(Keyword.t()) :: list()

Convert UDP options to :inet.setopts compatible arguments.

@spec open() :: {:ok, t()} | {:error, Error.t()}

Create a UDP socket listening on an OS chosen port, use local to know the port it was bound on.

@spec open(:inet.port_number() | Keyword.t()) :: {:ok, t()} | {:error, Error.t()}

Create a UDP socket listening on the given port or using the given options.

Link to this function

open(port, options)

@spec open(:inet.port_number(), Keyword.t()) :: {:ok, t()} | {:error, Error.t()}

Create a UDP socket listening on the given port and using the given options.

@spec open!() :: t() | no_return()

Create a UDP socket listening on an OS chosen port, use local to know the port it was bound on, raising if an error occurs.

Link to this function

open!(port_or_options)

@spec open!(:inet.port_number() | Keyword.t()) :: t() | no_return()

Create a UDP socket listening on the given port or using the given options, raising if an error occurs.

Link to this function

open!(port, options)

@spec open!(:inet.port_number(), Keyword.t()) :: t() | no_return()

Create a UDP socket listening on the given port and using the given options, raising if an error occurs.

Link to this function

options(socket, opts)

@spec options(t(), Keyword.t()) :: :ok | {:error, Error.t()}

Set options of the socket.

Link to this function

process(socket, pid)

@spec process(t() | port(), pid()) :: :ok | {:error, :closed | :not_owner | Error.t()}

Set the process which will receive the messages.

Link to this function

process!(socket, pid)

@spec process!(t() | port(), pid()) :: :ok | no_return()

Set the process which will receive the messages, raising if an error occurs.