Socket (a)

search keyword

java implementation to transfer files between the two servers manner
java file in TCP transport EXCLE
sockt
the JAVA httpClient POST request and the receiving sample code
java project HttpClient how to accept a request transmitted fastjson

 

Scene: In order to achieve the information exchange between the two systems, data transmission.

Adopt the way. Httpclient

What is HttpClient? What a scene to use HttpClient?

 

Three ways:

Technologies used:

The first way: stored procedures. Synonyms. About index? reflection

The second way: packet transmission. Multithreading. fastjson. httpclient.

The third way: socket to transfer files.

 

Process: implementation, documentation requirements == "interface documentation ==" == review "design documents ==" FBI

Interface documentation: implementation of data transmission (packet json??). Transfer field.

 

Requirements Document: Determine implementation.

Combined with business requirements, to determine the selection of the way.

 

Large quantities of data can be transmitted with the message. Packet transmission looks fairly standard.

 

Development of design documentation Related content:

The code is secondary, there are many online examples, the key is which way to transmit.

Log monitoring.

Interface to access timeout.

1, on the code: Online instance, combine to transform the business scene.

 

Foreword

File transfer between the two systems:

Way: Socket.

First, what is Socket

 

Second, the network transmission security simple setup

referer identify security chain security

 

getRemoteAddr () and getRemoteHost () difference

 

System.out.println("request.getRemoteAddr():    "    +    request.getRemoteAddr());      

System.out.println("request.getRemoteHost():    "    +    request.getRemoteHost());

 

The same result (the result of the test LAN).      

So getRemoteAddr () and getRemoteHost () in the end what is the difference?      

My goal is to get the issue request machine's IP address, which in the end by the above method?  

---------------------------------------------------------------  

 

It is a former client ip address  

After obtaining a host name of the client  

In the JSP, to obtain the IP address of the client's method is: request.getRemoteAddr (), this method is effective in most cases. But by the Apache, Squid reverse proxy and other software will not be able to get the real IP address of the client.

If you use a reverse proxy software, http://192.168.1.110:2046/ the reverse proxy URL into the URL http://www.xxx.com/ with request.getRemoteAddr () IP address acquisition method They are: 127.0.0.1 or 192.168.1.110, and not the client's real IP.

After the agent later, due to the increase between the client and the service intermediate layer, so the server can not directly get the client IP, server-side application can not directly address the return to forward the request to the client. However, the HTTP header information transfer request, adds X-FORWARDED-FOR information. Server address to track the original client IP address and the original client requests. When we visit http://www.xxx.com/index.jsp/, in fact, not that we really have access to the browser index.jsp file on the server, but the first by a proxy server to access http: //192.168. 1.110: 2046 / index.jsp, then access to the results of a proxy server returned to our browser, because it is a proxy server to access index.jsp, so index.jsp by request.getRemoteAddr () method to obtain the IP It is actually the address of the proxy server, not the client's IP address.

So we can obtain a method to get the client real IP address:

public String getRemortIP(HttpServletRequest request) {

  if (request.getHeader("x-forwarded-for") == null) {

   return request.getRemoteAddr();

  }

  return request.getHeader("x-forwarded-for");

 

 }

 

But when I visited http://www.xxx.com/index.jsp/, the IP address returned is always the unknown, also not shown above or 127.0.0.1 192.168.1.110, and I visit http: / /192.168.1.110:2046/index.jsp, then can return to the real IP address of the client, wrote a method to verify. The reason lies in the on Squid. squid.conf the default configuration file forwarded_for item is on, if forwarded_for set into the off: X-Forwarded-For: unknown

 

So way to get a client can be drawn from the real IP address of two:

 1    public String getIpAddr(HttpServletRequest request) {

 2        String ip = request.getHeader("x-forwarded-for");

 3        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

 4            ip = request.getHeader("Proxy-Client-IP");

 5        }

 6        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

 7            ip = request.getHeader("WL-Proxy-Client-IP");

 8        }

 9        if(ip == null || ip.length() == 0 || "unknown".equalsIgnoreCase(ip)) {

10            ip = request.getRemoteAddr();

11        }

12        return ip;

13    }

 

  However, if by a multi-stage reverse proxy, then the value of X-Forwarded-For and more than one, but a string value Ip, find out which is the real end user's real IP of it?

 

  The answer is to take the X-Forwarded-For the first non-valid IP unknown string.

 

  Such as:

  X-Forwarded-For:192.168.1.110, 192.168.1.120, 192.168.1.130, 192.168.1.100

  User real IP is: 192.168.1.110

 

 

 

 

 

 

Guess you like

Origin www.cnblogs.com/vole/p/11957273.html