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.
+2
A:
Ferruccio
2009-02-23 18:49:50
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
2009-02-23 18:53:00
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
2009-02-23 18:54:47
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
2009-02-23 18:56:27
I don't understand what you're asking. That code starts a server listening on port 13 (daytime service) already.
Ferruccio
2009-02-23 19:00:00
+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
2009-06-30 00:27:42
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
2010-03-03 13:23:50