Mailroom.Socket (Mailroom v0.2.6) View Source

Abstracts away working with normal sockets or SSL sockets.

Examples

{:ok, socket} = Mailroom.Socket.connect("localhost", 110)
{:ok, ssl_socket} = Mailroom.Socket.connect("localhost", 110, ssl: true)

Mailroom.Socket.send(socket, "Hello World")
Mailroom.Socket.send(ssl_socket, "Hello World")

Mailroom.Socket.close(socket)
Mailroom.Socket.close(ssl_socket)

Link to this section Summary

Functions

Closes the connection

Connect to a TCP server on port

Receive a line from the socket

Send data on a socket

Link to this section Types

Specs

t() :: %Mailroom.Socket{
  debug: term(),
  socket: term(),
  ssl: term(),
  timeout: term()
}

Link to this section Functions

Specs

close(t()) :: :ok

Closes the connection

Examples

:ok = Mailroom.Socket.close(socket)
Link to this function

connect(server, port, opts \\ [])

View Source

Specs

connect(String.t(), integer(), Keyword.t()) :: {:ok, t()} | {:error, String.t()}

Connect to a TCP server on port

The following options are available:

  • ssl - default false, connect via SSL or not
  • timeout - default 15000, sets the socket connect and receive timeout
  • debug - default false, if true, will print out connection communication

Examples

{:ok, socket} = Mailroom.Socket.connect("localhost", 110, ssl: true)

Specs

recv(t()) :: {:ok, String.t()} | {:error, String.t()}

Receive a line from the socket

Examples

{:ok, line} = Mailroom.Socket.recv(socket)

Specs

send(t(), String.t()) :: :ok | {:error, String.t()}

Send data on a socket

Examples

:ok = Mailroom.Socket.send(socket)