View Source Mailroom.Socket (Mailroom v0.5.0)

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)

Summary

Functions

Closes the connection

Connect to a TCP server on port

Receive a line from the socket

Send data on a socket

Types

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

Functions

@spec close(t()) :: :ok

Closes the connection

Examples

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

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

View Source
@spec 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)
@spec recv(t()) :: {:ok, String.t()} | {:error, String.t()}

Receive a line from the socket

Examples

{:ok, line} = Mailroom.Socket.recv(socket)
@spec send(t(), String.t()) :: :ok | {:error, String.t()}

Send data on a socket

Examples

:ok = Mailroom.Socket.send(socket)