Question

I'm trying to work with Boost Asio instead of RakNet so I was trying to follow along with the examples on the Boost website but I have some questions left unanswered. Here's the link: http://www.boost.org/doc/libs/1_55_0/doc/html/boost_asio/tutorial/tutdaytime1.html

Just a heads up, I got the tutorial working, both the client and the server.

1) Why does the query need the string "daytime"? It's nowhere to be found in the server setup. The client only seems to connect when I'm using that string. (Tried with "test" and it didn't connect)

2) Why don't I need to give the client a port to connect to? Does it search for this port itself or is there and option to set this up manually as well?

Thanks in advance.

Was it helpful?

Solution

    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 :))

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top