+2  A: 

You are telling it that you want to connect to localhost on the port used by the daytime service. It will look up the appropriate port number in the services file (usually C:\WINDOWS\system32\drivers\etc\services under Windows, I believe /etc/services under Unix). You could also use an explicit port number there.

Ferruccio
I didn`t quite understand what the second parameter means in query ctor. the first one is IP address I want to connect to, right? and what does the second mean?
chester89
The second parameter is either a port number or the name of a service. If it is a service name, asio will look it up in the services file to find the appropriate port number for that service. Take a look at the services file with a text editor and you will see how it works.
Ferruccio
ok, then how can I start a server on a port I need? code for that on server side is:boost::asio::io_service io_service;tcp::acceptor acceptor(io_service, tcp::endpoint(tcp::v4(), 13));
chester89
I don't understand what you're asking. That code starts a server listening on port 13 (daytime service) already.
Ferruccio
+1  A: 

Try,

tcp::resolver::query query("localhost", boost::lexical_cast<string>(port));//assuming port is an int

To answer your question, recall that you are starting the server on port 13. This happens to be the port which runs the Linux daytime service (http://www.sorgonet.com/linux/linuxdaemons/). Hence, they are subsequently able to use query("localhost","daytime") rather than specifying the port.

imran.fanaswala
A: 

open netcat listen on port 13 on the localhost it will accept the demo's connection. type some blabla when it connects and you'll see the output on the demo program to run the netcat, run: nc -l -p 13

windows? no netcat? install cygwin, and add netcat

nir