Mailroom v0.2.1 Mailroom.Socket 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

Link to this type

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

Link to this section Functions

Link to this function

close(socket) View Source
close(t()) :: :ok

Closes the connection

Examples

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

connect(server, port, opts \\ []) View Source
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)
Link to this function

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

Receive a line from the socket

Examples

{:ok, line} = Mailroom.Socket.recv(socket)
Link to this function

send(socket, data) View Source
send(t(), String.t()) :: :ok | {:error, String.t()}

Send data on a socket

Examples

:ok = Mailroom.Socket.send(socket)