tcp::resolver::query query(argv[1], "daytime");
This lines resolves an endpoint, where argv[1]
is the host, and "daytime"
represents the port. Yeah, that's a little surprising, as you'd expect something like 80
or 443
there. However, what you see is the service-name which (like hostnames) can be used instead of a hardcoded port, and gets resolved by the operating system.
If hostnames are resolved via /etc/hosts
, services are resolved via /etc/services
(or C:\WINDOWS\system32\drivers\etc\services
I suppose).
On my system this file contains:
daytime 13/tcp
daytime 13/udp
So, in fact you could just use "13"
instead of "daytime"
. Note that this is the default port for the system daytime service. It "works" because your system answers on that port. (Or because your server is already running and uses that port, I don't know which server you run and how :))