aboutsummaryrefslogtreecommitdiffstats
path: root/doc/src/manual/gun.open.asciidoc
blob: 63bb3f85f976f7609095540e2bb74c8c76141f4b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
= gun:open(3)

== Name

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

== Description

[source,erlang]
----
open(Host, Port)       -> open(Host, Port, #{})
open(Host, Port, Opts) -> {ok, pid()} | {error, Reason}

Host    :: inet:hostname() | inet:ip_address()
Port    :: inet:port_number()
Opts    :: gun:opts()
Reason  :: {options, OptName}
         | {options, {http | http2 | socks | ws, OptName}}
         | any()
OptName :: atom()
----

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 link:man:gun_up(3)[gun_up(3)]
message will be sent for that.

== Changelog

* *1.0*: Function introduced.

== Examples

.Connect to a server
[source,erlang]
----
{ok, ConnPid} = gun:open("example.org", 443).
----

.Connect to a server with custom options
[source,erlang]
----
{ok, ConnPid} = gun:open("example.org", 443,
    #{protocols => [http2]}).
----

.Connect to a server using its IP address
[source,erlang]
----
{ok, ConnPid} = gun:open({127,0,0,1}, 443).
----

== See also

link:man:gun(3)[gun(3)],
link:man:gun:open_unix(3)[gun:open_unix(3)],
link:man:gun:await_up(3)[gun:await_up(3)],
link:man:gun_socks_up(3)[gun_socks_up(3)],
link:man:gun_up(3)[gun_up(3)]