Create an iostream using boost asio specifying ip and port

后端 未结 3 1635
春和景丽
春和景丽 2021-02-06 10:36

I have a problem concerning boost asio libraries. I successfully tried to create a socket between a client and a server, this involves creation of resolvers in order to specify

3条回答
  •  悲哀的现实
    2021-02-06 11:22

    The boost asio sample code you quoted:

    tcp::iostream s(argv[1], "daytime");
    

    uses "daytime" as a lookup into the services table (usually in /etc/services on a linux system), which would identify that the port for the daytime service is 13.

    If you want to connect to a port that is not one of the well known services, you can do so with something like:

    tcp::iostream s("localhost", "57002"); 
    

    Note that the port number is supplied as a string, not as an unsigned short integer as one might be tempted to try.

    Of course, "localhost" can be replaced with an IP address "127.0.0.1"

提交回复
热议问题