TCP/IP Networking with Boost.Asio

Поділитися
Вставка
  • Опубліковано 4 лис 2024

КОМЕНТАРІ • 15

  • @UtahCppProgrammers
    @UtahCppProgrammers  Рік тому +3

    To stop an io_context from running out of work, use the executor_work_guard; this is what I was trying to remember at the end of the video :). See the documentation here:
    www.boost.org/doc/libs/1_81_0/doc/html/boost_asio/reference/io_context.html#boost_asio.reference.io_context.stopping_the_io_context_from_running_out_of_work

  • @bzdzgwa
    @bzdzgwa Рік тому

    One thing you haven't mentioned. If the program waits for a data to send to the server (from a user for example) and there are no asynchronous read/write operations pending, you recommended using executor_work_guard, to keep io_context.run() method busy. But what if the server closes the connection at that moment. How the program will know about this?

    • @UtahCppProgrammers
      @UtahCppProgrammers  Рік тому

      If you are attempting to send/receive data to/from a server and it closes the connection, your handler is invoked with an error code indicating the connection was closed. TCP/IP has a specific sequence that the socket goes through in the protocol in order to indicate that one side has closed the connection cleanly. If the other end of a socket just crashes, then you get an error code when you attempt to read or write on that connection, possibly after a timeout period (e.g. you are waiting for acknowledgement of sent data and it doesn't arrive before the timeout).

    • @bzdzgwa
      @bzdzgwa Рік тому

      If I wanted to be notified immediately if the server closed the connection gracefully, should I always have async_read in the background? Will the async_read handler be invoked immediately with an error in such case?

    • @UtahCppProgrammers
      @UtahCppProgrammers  Рік тому +1

      @@bzdzgwa In TCP/IP, when one side closes the connection a FIN packet is sent. So if the server closes the connection, you would get this notification as an error code the next time you attempt to do anything with the connection. That's how I understand it. My advice is to write a simple program and test it out to find out what the exact behavior will be. You can use the sample code I wrote in the linked github repository to try this.

  • @victorrico-z4b
    @victorrico-z4b 8 місяців тому

    An IPv6 address is 128 bits not 64. You stated it was 4 x 16 bits. You may be thinking of the host portion of the address, but you'd need to know the full address to communicate.

  • @vadiks20032
    @vadiks20032 Рік тому

    how did you make CMD divide itself by 4 in the single window? is it CMD feature or just some code to make it look like that

    • @UtahCppProgrammers
      @UtahCppProgrammers  Рік тому +1

      I'm using the curses library to create text windows. On Windows, the implementation of the curses library is provided by pdcurses; on Linux the implementation comes from ncurses, which is usually installed on the system and not through vcpkg.
      You can read about the curses API here: invisible-island.net/ncurses/man/ncurses.3x.html

  • @АртемЗебелян-ш9р

    Can you help me with source of knowledges about boost::asio. Now I do my course work. And the main task is to create client-server application to send messages between clients.
    So, where I can read more about this topic.
    I ask this question because there are a lot of sources, but information there is not clear.

  • @LavinOficial
    @LavinOficial Рік тому

    Could you make a boost asio video that handles the json protocol for a communication with python flask please

    • @alang.2054
      @alang.2054 2 місяці тому

      Don't use python! 😂

  • @UtahCppProgrammers
    @UtahCppProgrammers  Рік тому

    Example source code: github.com/LegalizeAdulthood/asio-tcp-ip

    • @chaojiang5336
      @chaojiang5336 11 днів тому

      I tried to compile in Linux (with some modifications in source file and cmake) and was able to build the news-reader application, but when running it I got no messages printed out but just an entirely empty window. Do you have any idea about that?