[
Date Prev][
Date Next][
Thread Prev][
Thread Next][
Date Index][
Thread Index]
[
List Home]
Re: [jetty-users] How to set the local IP address when using Http2Client to send http2 request out
|
Hi,
On Wed, Nov 1, 2017 at 3:23 AM, Cao, William (NSB - CN/Qingdao)
<william.cao@xxxxxxxxxxxxxxx> wrote:
> Hi,
>
> I am trying to use Jetty 9.4.7 + JDK1.8.0_141 as the HTTP2 client. I used
> the sample code in below link. In my client host, there are multiple IP
> addresses. Since there is no local IP address specified in the code, the
> client will use one as the local ip address to send the http2 request out.
> However, I need to set the local IP address but not to use the default one.
> How to set the local IP address before sending out the request?
This functionality is available if you use Jetty's HttpClient with the
HTTP/2 transport, see
http://www.eclipse.org/jetty/documentation/current/http-client-transport.html#_http_2_transport.
With that setup, you can do:
HTTP2Client h2Client = new HTTP2Client();
HttpClientTransportOverHTTP2 transport = new
HttpClientTransportOverHTTP2(h2Client);
HttpClient client = new HttpClient(transport, null);
client.setBindAddress(<your local address here>);
client.start();
If you want to use directly the low-level HTTP2Client, you can do it
in this way:
HTTP2Client h2Client = new HTTP2Client() {
@Override
protected void configure(SocketChannel channel) throws IOException {
super.configure(channel);
channel.bind(<your local address here>);
}
};
Cheers
--
Simone Bordet
----
http://cometd.org
http://webtide.com
Developer advice, training, services and support
from the Jetty & CometD experts.