Java Network access specified egress IP

Source: Internet
Author: User

Java network access specified exits iptable of Contents
    • 1. Socket
    • 2. Apache HttpClient
1Socket

You can specify the local IP that is used in the socket constructor, such as:

Socket socket = new Socket ("127.0.0.1", 12345, Inetaddress.getbyaddress (new byte[] {                new Integer). Bytevalue (), C4/>new Integer (211). Bytevalue (),                New Integer (. Bytevalue (),                new Integer (2). Bytevalue (),        }), 1234);
2Apache HttpClient

It can be set by HttpClient, as follows:

byte b[] = new Byte[4];b[0] = new Integer (Ten). Bytevalue (); b[1] = new Integer (211). Bytevalue (); b[2] = new integer. Bytev Alue (); b[3] = new Integer (2). Bytevalue (); Closeablehttpresponse response = null; Closeablehttpclient httpclient = Httpclients.createdefault (); HttpGet httpget = new HttpGet ("Http://localhost:8080/TestServlet"); Httpget.setconfig (Requestconfig.custom ()        . Setlocaladdress (inetaddress.getbyaddress (b))        . Build ());

Author:galaxy

created:2016-08-31 Wed 17:11

Emacs 24.5.6 (ORG mode 8.2.10)

Validate

Java Network access specified egress IP

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.