| 1 |
= cowboy_req:sock(3) |
| 2 |
|
| 3 |
== Name |
| 4 |
|
| 5 |
cowboy_req:sock - Socket address and port |
| 6 |
|
| 7 |
== Description |
| 8 |
|
| 9 |
[source,erlang] |
| 10 |
---- |
| 11 |
sock(Req :: cowboy_req:req()) -> Info |
| 12 |
|
| 13 |
Info :: {inet:ip_address(), inet:port_number()} |
| 14 |
---- |
| 15 |
|
| 16 |
Return the socket's IP address and port number. |
| 17 |
|
| 18 |
The socket information can also be obtained using pattern matching: |
| 19 |
|
| 20 |
[source,erlang] |
| 21 |
---- |
| 22 |
#{sock := {IP, Port}} = Req. |
| 23 |
---- |
| 24 |
|
| 25 |
== Arguments |
| 26 |
|
| 27 |
Req:: |
| 28 |
|
| 29 |
The Req object. |
| 30 |
|
| 31 |
== Return value |
| 32 |
|
| 33 |
The socket's local IP address and port number. |
| 34 |
|
| 35 |
== Changelog |
| 36 |
|
| 37 |
* *2.1*: Function introduced. |
| 38 |
|
| 39 |
== Examples |
| 40 |
|
| 41 |
.Get the socket's IP address and port number. |
| 42 |
[source,erlang] |
| 43 |
---- |
| 44 |
{IP, Port} = cowboy_req:sock(Req). |
| 45 |
---- |
| 46 |
|
| 47 |
== See also |
| 48 |
|
| 49 |
link:man:cowboy_req(3)[cowboy_req(3)], |
| 50 |
link:man:cowboy_req:peer(3)[cowboy_req:peer(3)], |
| 51 |
link:man:cowboy_req:cert(3)[cowboy_req:cert(3)] |