diff --git a/include/krpc/connection.hpp b/include/krpc/connection.hpp
index eac293f..6307c7b 100644
--- a/include/krpc/connection.hpp
+++ b/include/krpc/connection.hpp
@@ -7,7 +7,7 @@
 #ifndef ASIO_STANDALONE
 #define ASIO_STANDALONE
 #endif
-#include <asio/io_service.hpp>
+#include <asio/io_context.hpp>
 #include <asio/ip/tcp.hpp>
 // IWYU pragma: no_include <asio/impl/io_service.ipp>
 
@@ -29,7 +29,7 @@ class Connection {
   std::string partial_receive(size_t length,
                               std::chrono::milliseconds timeout = std::chrono::milliseconds(10));
  private:
-  asio::io_service io_service;
+  asio::io_context io_service;
   asio::ip::tcp::socket socket;
   const std::string address;
   const unsigned int port;
diff --git a/src/connection.cpp b/src/connection.cpp
index 22db1ff..ca0df4f 100644
--- a/src/connection.cpp
+++ b/src/connection.cpp
@@ -29,9 +29,8 @@ Connection::Connection(const std::string& address, unsigned int port):
 void Connection::connect() {
   std::ostringstream port_str;
   port_str << port;
-  asio::ip::tcp::resolver::query query(asio::ip::tcp::v4(), address, port_str.str());
-  asio::ip::tcp::resolver::iterator iterator = resolver.resolve(query);
-  asio::connect(socket, iterator);
+  auto result = resolver.resolve(asio::ip::tcp::v4(), address, port_str.str());
+  asio::connect(socket, result);
 }
 
 void Connection::send(const char* data, size_t length) {
@@ -70,7 +69,7 @@ std::string Connection::partial_receive(size_t length, std::chrono::milliseconds
 
   bool timer_complete = false;
   asio::steady_timer timer(socket.get_executor());
-  timer.expires_from_now(timeout);
+  timer.expires_after(timeout);
   timer.async_wait(
     [&timer_complete] (const asio::error_code& error) {
       timer_complete = true;
@@ -84,7 +83,7 @@ std::string Connection::partial_receive(size_t length, std::chrono::milliseconds
       read_complete = true;
     });
 
-  io_service.reset();
+  io_service.restart();
   while (io_service.run_one()) {
     if (read_complete)
       timer.cancel();
