:relfileprefix: ../../../
[#boost-urls-url-set_port_number]

= xref:boost.adoc[pass:[boost]]::xref:boost/urls.adoc[pass:[urls]]::xref:boost/urls/url.adoc[pass:[url]]::set_port_number


Set the port


== Synopsis

Declared in header `<https://www.github.com/boostorg/url/blob/develop/include/boost/url/url.hpp#L456[boost/url/url.hpp,window=blank_]>`

[source,cpp,subs="verbatim,macros,-callouts"]
----
xref:boost/urls/url.adoc[url]&
set_port_number(xref:std.adoc[std]::uint16_t n);
----

== Description


The port is set to the specified integer.

=== Example
[,cpp]
----
assert( url( "http://www.example.com" ).set_port_number( 8080 ).authority().buffer() == "www.example.com:8080" );
----

=== Postconditions
[,cpp]
----
this->has_authority() == true && this->has_port() == true && this->port_number() == n
----

=== Complexity

Linear in `this-&gt;size()`.

=== Exception Safety

Strong guarantee.
Calls to allocate may throw.

=== BNF
[,cpp]
----
authority     = [ userinfo "@" ] host [ ":" port ]

port          = *DIGIT
----

=== Specification

* link:https://datatracker.ietf.org/doc/html/rfc3986#section-3.2.3[            3.2.3. Port (rfc3986)]





== Parameters

|===
| Name | Description 

| *n*
| 
The port number to set.

|===




== See Also


xref:boost/urls/url_base/remove_port.adoc[remove_port]
,
xref:boost/urls/url_base/set_port.adoc[set_port]
.



