Debian Codegraph @

doc/src/manual/cowboy.start_clear.asciidoc

raw
1 = cowboy:start_clear(3)
2
3 == Name
4
5 cowboy:start_clear - Listen for connections using plain TCP
6
7 == Description
8
9 [source,erlang]
10 ----
11 start_clear(Name :: ranch:ref(),
12 TransportOpts :: ranch_tcp:opts(),
13 ProtocolOpts :: opts())
14 -> {ok, ListenerPid :: pid()}
15 | {error, any()}
16 ----
17
18 Start listening for connections over a clear TCP channel.
19
20 Both HTTP/1.1 and HTTP/2 are supported on this listener.
21 HTTP/2 has two methods of establishing a connection over
22 a clear TCP channel. Both the upgrade and the prior knowledge
23 methods are supported.
24
25 == Arguments
26
27 Name::
28
29 The listener name is used to refer to this listener in
30 future calls, for example when stopping it or when
31 updating the routes defined.
32 +
33 It can be any Erlang term. An atom is generally good enough,
34 for example `api`, `my_app_clear` or `my_app_tls`.
35
36 TransportOpts::
37
38 The transport options are where the TCP options, including
39 the listener's port number, are defined. Transport options
40 are provided as a list of keys and values, for example
41 `[{port, 8080}]`.
42 +
43 The available options are documented in the
44 link:man:ranch_tcp(3)[ranch_tcp(3)] manual.
45
46 ProtocolOpts::
47
48 The protocol options are in a map containing all the options for
49 the different protocols that may be involved when connecting
50 to the listener, including HTTP/1.1 and HTTP/2.
51 +
52 The HTTP/1.1 options are documented in the
53 link:man:cowboy_http(3)[cowboy_http(3)] manual;
54 and the HTTP/2 options in
55 link:man:cowboy_http2(3)[cowboy_http2(3)]. Stream handlers
56 such as link:man:cowboy_stream_h(3)[cowboy_stream_h(3)]
57 (which is enabled by default) may also define options.
58
59 == Return value
60
61 An ok tuple is returned on success. It contains the pid of
62 the top-level supervisor for the listener.
63
64 An error tuple is returned on error. The error reason may
65 be any Erlang term.
66
67 A common error is `eaddrinuse`. It indicates that the port
68 configured for Cowboy is already in use.
69
70 == Changelog
71
72 * *2.0*: HTTP/2 support added.
73 * *2.0*: Function introduced. Replaces `cowboy:start_http/4`.
74
75 == Examples
76
77 .Start a listener
78 [source,erlang]
79 ----
80 Dispatch = cowboy_router:compile([
81 {'_', [
82 {"/", toppage_h, []}
83 ]}
84 ]),
85
86 {ok, _} = cowboy:start_clear(example, [{port, 8080}], #{
87 env => #{dispatch => Dispatch}
88 }).
89 ----
90
91 .Start a listener on a random port
92 [source,erlang]
93 ----
94 Name = example,
95
96 {ok, _} = cowboy:start_clear(Name, [], #{
97 env => #{dispatch => Dispatch}
98 }),
99
100 Port = ranch:get_port(Name).
101 ----
102
103 == See also
104
105 link:man:cowboy(3)[cowboy(3)],
106 link:man:cowboy:start_tls(3)[cowboy:start_tls(3)],
107 link:man:cowboy:stop_listener(3)[cowboy:stop_listener(3)],
108 link:man:ranch(3)[ranch(3)]