gun:open(3)

Name

gun:open - Open a connection to the given host and port

Description

open(Host, Port)       -> open(Host, Port, #{})
open(Host, Port, Opts) -> {ok, pid()} | {error, any()}

Host :: inet:hostname() | inet:ip_address()
Port :: inet:port_number()
Opts :: gun:opts()

Open a connection to the given host and port.

Arguments

Host

Host or IP address to connect to.

Port

Port to connect to.

Opts

Options for this connection.

Return value

The pid of the newly created Gun process is returned. Note that this does not indicate that the connection has been successfully opened; the gun_up(3) message will be sent for that.

Changelog

  • 1.0: Function introduced.

Examples

Connect to a server
{ok, ConnPid} = gun:open("example.org", 443).
Connect to a server with custom options
{ok, ConnPid} = gun:open("example.org", 443,
    #{protocols => [http2]}).
Connect to a server using its IP address
{ok, ConnPid} = gun:open({127,0,0,1}, 443).

See also

gun(3), gun:open_unix(3), gun:await_up(3), gun_up(3)

Gun 1.0 Function Reference

Navigation

Version select

Like my work? Donate!

Donate to Loïc Hoguin because his work on Cowboy, Ranch, Gun and Erlang.mk is fantastic:

Recurring payment options are also available via BountySource. These funds are used to cover the recurring expenses like dedicated servers or domain names.