sony / easyhttpcpp

A cross-platform HTTP client library with a focus on usability and speed
MIT License
163 stars 29 forks source link

How can i create a long connection use this ? #12

Open SloanAufderstrase opened 4 years ago

SloanAufderstrase commented 4 years ago

Brief overview

Hi, I'm new to network programming, i want to use this library to write a simple http client. But i don't know how to create a long connection by this library, i want send multiple http request in one connection. Could someone please help me?

shekharhimanshu commented 4 years ago

Hi @SloanAufderstrase

Thank you for your interest in EasyHttp.

EasyHttp supports connection pooling. Have a look at the SimpleHttpClient sample.

You can configure a connection pool when creating EasyHttp client instance.

SloanAufderstrase commented 4 years ago

Hi @SloanAufderstrase

Thank you for your interest in EasyHttp.

EasyHttp supports connection pooling. Have a look at the SimpleHttpClient sample.

You can configure a connection pool when creating EasyHttp client instance.

Think you for your fast response. I like EasyHttp.

I have read SimpleHttpClient sample. I would like to read the source code too, but now i don't have much time. So maybe my question it too naive. The question is: i don't know how to reuse the connection in the connection pool. Could you give me a code piece about that please?

shekharhimanshu commented 4 years ago

i don't know how to reuse the connection in the connection pool. Could you give me a code piece about that please?

Ah, EasyHttp will take care of connection pooling automatically for you once configured. When configuring the connection pool, you can set two parameters as shown below:

  1. Maximum no of idle collections in connection pool
  2. Keep-alive timeout in seconds
//max no of idle collections in connection pool
unsigned int keepAliveIdleCountMax = 10;
// keep-alive timeout second
unsigned long keepAliveTimeoutSec = 60;

// EasyHttp will keep-alive keepAliveIdleCountMax idle connections in parallel for keepAliveTimeoutSec seconds
easyhttpcpp::ConnectionPool::Ptr pConnectionPool = easyhttpcpp::ConnectionPool::createConnectionPool(keepAliveIdleCountMax, keepAliveTimeoutSec);
Yashyk456 commented 11 months ago

i don't know how to reuse the connection in the connection pool. Could you give me a code piece about that please?

Ah, EasyHttp will take care of connection pooling automatically for you once configured. When configuring the connection pool, you can set two parameters as shown below:

  1. Maximum no of idle collections in connection pool
  2. Keep-alive timeout in seconds
//max no of idle collections in connection pool
unsigned int keepAliveIdleCountMax = 10;
// keep-alive timeout second
unsigned long keepAliveTimeoutSec = 60;

// EasyHttp will keep-alive keepAliveIdleCountMax idle connections in parallel for keepAliveTimeoutSec seconds
easyhttpcpp::ConnectionPool::Ptr pConnectionPool = easyhttpcpp::ConnectionPool::createConnectionPool(keepAliveIdleCountMax, keepAliveTimeoutSec);

@shekharhimanshu I understood what you have explained , can you please tell then what does setCorePoolSizeOfAsyncThreadPool and setMaximumPoolSizeOfAsyncThreadPool do and what is their role


 httpClientBuilder.setConnectionPool(pConnectionPool)
        .setCorePoolSizeOfAsyncThreadPool(10)
        .setMaximumPoolSizeOfAsyncThreadPool(10 + no_of_cores);