c++ - Boost asio ip tcp iostream Error Detection -


Greetings I'm just starting to promote: In the beginning of the ASIO Library and promoting some of the early difficulties. : Asio :: ip :: tcp :: iostream

My question has two parts:

1) How does an iostream connect by using a host and port number?

I and [boost.org] examples can work fine in coded form. The server explicitly specifies the port:

  boost :: asio :: io_service io_service; Tcp :: End Point Endpoint (TCP :: V4 (), 13); TCP :: acceptor acceptor (io_service, end point);  

Port 13 is a famous port for "time of day" service.

The client's example connects by specifying a host and service name:

  tcp :: iostream s (argv [1], "time of day");  

For my own application, I want to put the server on an arbitrary port and connect to the number as shown below:

Server: < / P>

  Promotion: asio :: io_service io_service; Tcp :: End Point Endpoint (TCP :: V4 (), Port); TCP :: acceptor acceptor (io_service, end point); Acceptor.accept (* this-> socketStream.rdbuf ()); ...  

Customer:

  Promotion :: asio :: ip :: tcp :: iostream sockstream; ... sockstream.connect ("localhost", port); ...  

If, in the customer, I try to specify the port number directly (instead of a service by name), the stream fails to connect. Is there any way of doing it? It is not clear whether the logic should be / what to connect.


2. What is the best way to test the success of call to Iostream :: connect?

The function returns zero, and no exception is thrown. The only way I have prepared so far is to test this stream. File () and / or stream.good () Is this the way to do it, or any other way.


Advice on one or both of these will be appreciated. Apart from this, if I am ignoring proper documentation and / or examples, it would be good to do so so far I could not answer the questions by reading the library docs or searching the net.

I do not know why ASIO does not work (at least with boost 1.35.0) A port number was expressed as an int but, you can specify the port number as a string. I.e.

  tcp :: iostreams (hostname, "13");   

takes up and is a reference to the endpoint and boost :: system :: error_code object which will tell you that it is successfully connected.


Comments

Popular posts from this blog

c++ - Linux and clipboard -

What is expire header and how to achive them in ASP.NET and PHP? -

sql server - How can I determine which of my SQL 2005 statistics are unused? -