When the server needs to be started during development, local testing directly writes the port, and the actual environment also requires specifying the IP to be bound. Because sometimes the server has more than one network card, and our system must communicate through the specified IP and port, so the IP and port used by the server need to define the configuration file. So in normal testing, when no IP is specified, where does ServerSocket bind to? In this case, the server will bind this port to 0.0.0.0, that is, it will bind it to all IPs, and can receive requests on each IP. As for what 0.0.0.0 is, I won’t explain it here. The following is a test program, through the following program you can see what the situation is: package test; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; public class Test { public static void main(String[] args) throws Exception { SocketClient client = new SocketClient(); new Thread(client).start(); ServerSocket serverSocket = new ServerSocket(); serverSocket.bind(new InetSocketAddress(8888)); // serverSocket.bind(new InetSocketAddress("127.0.0.1",8888)); // serverSocket.bind(new InetSocketAddress("192.168.1.100",8888)); System.out.println(serverSocket.toString()); serverSocket.accept(); } } class SocketClient implements Runnable{ public void run() { try { Thread.sleep(2000); try { Socket socket = new Socket("127.0.0.1", 8888); System.out.println("127.0.0.1 success" + socket.toString()); } catch (Exception e) { System.err.println("127.0.0.1 failed"); } try { Socket socket = new Socket("192.168.1.100", 8888); System.out.println("192.168.1.100 success" + socket.toString()); } catch (Exception e) { System.err.println("192.168.1.100 failed"); } } catch (Exception e) { e.printStackTrace(); } } } The print result at this time is:
Print results when using 127.0.0.1:
Print results when using 192.168.1.100:
You can see that the default binding is 0.0.0.0. At this time, you can use any IP that can be marked to this computer to access port 8888. Of course, this is not a verification of dual network cards, because I am still playing on one network card. If conditions permit, you can do a small test on a blade machine. The above is the full content of this article. I hope it will be helpful for everyone’s study. I also hope that everyone will support 123WORDPRESS.COM. You may also be interested in:
|
<<: Differences between MySQL CHAR and VARCHAR when storing and reading
>>: Vue3 encapsulates its own paging component
background There is a requirement in the project ...
What is element-ui element-ui is a desktop compon...
1. Docker startup problem: Problem Solved: You ne...
Table of contents Preface Demand Analysis Mysql u...
Learning Linux commands is the biggest obstacle f...
Table of contents Since Vuex uses a single state ...
Docker basic instructions: Update Packages yum -y...
1. Download related tools and images Download Lin...
It is really not easy to do a good reconstruction...
After the article "This Will Be a Revolution&...
This article example shares the specific code for...
IIS7 Download the HTTP Rewrite module from Micros...
This article shares the specific code of JavaScri...
1.1 Introduction to iptables firewall Netfilter/I...
Since Uniapp does not have DingTalk authorization...