[Unity] Create the project environment with githubdesktop management GIT code installation process FMJ

2023-01-23   ES  

UDP information transmission method

single broadcast (unicast):

refers to a method of transmission in the transmission of the packet in the transmission of the computer network. The destination address is a single target. It is the most widely used in network applications today. Most of the network protocols or services used in generally use single -broadcast transmission, such as all TCP -based protocols.

Multicast:

Also called multi -broadcast, multi -point broadcast or group broadcast. Refers to passing the information to a set of destination addresses at the same time. It uses the strategy the most efficient, because the message only needs to be passed once on each network link, and the message will be copied only when the link is fork.

Multi -broadcast group specifies through the DP address and standard UDP port number. Class D IP address is within the range of 224.0.0.0 and 239.255.255.255 (including two). Address 224.0.0.0 is retained and should not be used.

Radio (Broadcast):

refers to a method of transmission of all devices in the network when the packet is transmitted in the computer network. In fact, the “all equipment” mentioned here is also limited to a scope, called “broadcast domain”.

Detailed introduction (from Wikipedia)

Single broadcast:

There are only two entities to communicate with each other at a time, and the sending end and receiving end are unique.

In the IPv4 network, 0.0.0.0 to 223.255.255.255 belongs to a single -broadcast address.

You shouted “Xiao Yueyue” to Xiaoyue Yue, so only Xiaoyue Yue turned back to promise you.

Circular:

“Drate” is usually used to refer to IP broadcast. IP broadcast is an agreement to send data to multiple receivers on the TCP/IP network by using a transliterate address at the same time. In addition, it is often used to combine audio and video protocols such as RTP.

Internet architect Dave Clark described the IP program: “If you put the packet from one end, the Internet will try to pass them to those who want to get them.”

The destination address of the

Broadcasting packet uses the D type of IP address, and the type D address cannot appear in the source IP address field of the IP message.

You shouted “Beauty” on the street, there will be a group of women looking back at you.

Broadcast address (refer to IANA)

The

orite can be permanent or temporary. In the address of the broadcasting group, some of them are officially assigned, called permanent group broadcasting group. The permanent group broadcasting group remains unchanged is its IP address, and the member composition in the group can change. The number of members in the permanent group can be arbitrarily or even zero. Those IP broadcast addresses that have not been retained for permanent broadcast groups can be used by the temporary broadcast group.

  • 224.0.0.0 ~ 224.0.0.255 is the reserved programming address (permanent group address), the address 224.0.0.0 is retained without allocating, and other addresses are used for routing protocols;
  • 224.0.1.0 ~ 224.0.1.255 is the public bother address, Internetwork Control Block;
  • 224.0.2.0 ~ 238.255.255.255 is the operating address (temporary group address) that can be available for users, which is valid on the entire network;
  • 239.0.0.0 ~ 239.255.255.255 is the local management bile address, which is effective within a specific local area.

Permanent programming address:

  • 224.0.0.0 benchmark address (reserved)
  • 224.0.0.1 The address of all hosts (including all routers)
  • 224.0.0.2 The address of all the operators
  • 224.0.0.3 No allocation
  • 224.0.0.4 DVMRP router
  • 224.0.0.5 All OSPF routers
  • 224.0.0.6 ospf DR/BDR
  • 224.0.0.7 ST router
  • 224.0.0.8 ST host
  • 224.0.0.9 RIP-2 router
  • 224.0.0.10 EIGRP router
  • 224.0.0.11 Activity proxy
  • 224.0.0.12 DHCP server/relay agent
  • 224.0.0.13 All PIM routers
  • 224.0.0.14 RSVP package
  • 224.0.0.15 All CBT routers
  • 224.0.0.16 Specify SBM
  • 224.0.0.17 All SBMS
  • 224.0.0.18 vrrp

When the Ethernet transmits a single -broadcast IP message, the target MAC address uses the MAC address of the receiver. However, during the transmission group, the transmission purpose is no longer a specific receiver, but a group that members are uncertain, so the MAC address is used. The MAC address is corresponding to the IP address of the broadcast. IANA (Internet Assigned Number Authority) stipulates that the high 24bit of the MAC address is 0x01005e, and the low 23bit of MAC address is the low 23bit of the broadcast IP address.

Due to the latter 28 bits of the IP programming address, only 23 digits are mapped to the MAC address, so 32 IP -ide link addresses will be mapped to the same MAC address.

Broadcast:

Not all computer networks support broadcasting. For example, the X.25 network and frame relay do not support broadcasting, and there is no broadcast in the “entire Internet”. IPv6 does not support broadcasting, and the corresponding functions of the broadcast are replaced by the broadcast.

Generally, broadcasting is limited to the local area network, such as Ethernet or token ring network. Because the impact of broadcasting in the local area network is much smaller than the wide area network.

The

Ethernet and IPv4 network use the address of all 1 to represent the broadcast, which are FF: FF: FF: FF: FF: FF: FF: FF and 255.255.255.255.

The
token ring network uses IEEE 802.2 to control a special value in the control domain to represent broadcasting.

You shouted “Holiday” in the company, all colleagues responded and yelled to death.

java Socket programming based on UDP

Single broadcast:

ChatDemo.java

  1. package udp;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.net.DatagramPacket;
  6. import java.net.DatagramSocket;
  7. import java.net.InetAddress;
  8. import java.net.SocketException;
  9. /**
  10.  *
  11.  *
  12. *Writing a chat tool
  13. *There is a data part, and the data sends data part
  14. *These two are not performed at the same time
  15. *Multi -threaded technology
  16. *A thread control collection, a thread control sending
  17.  *
  18. *Because it is inconsistent with the collection and mobility, two methods must be defined
  19. *and these two methods need to be encapsulated into different categories
  20.  *
  21. *@author words 6
  22. *@date 2017/12/6 PM 8:25
  23.  */
  24. class Send implements Runnable {
  25.     private DatagramSocket socket;
  26.     public Send(DatagramSocket socket) {
  27.         this.socket = socket;
  28.     }
  29.     @Override
  30.     public void run() {
  31.         try {
  32.             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  33.             String line = null;
  34.             while((line = bufferedReader.readLine()) != null) {
  35.                 byte[] buff = line.getBytes();
  36.                 DatagramPacket packet = new DatagramPacket(buff,buff.length, InetAddress.getByName(“192.168.168.106”),10001);
  37.                 socket.send(packet);
  38.                 if(“bye”.equals(line)) {
  39.                     break;
  40.                 }
  41.             }
  42.             socket.close();
  43.         } catch (IOException e) {
  44.             e.printStackTrace();
  45.         }
  46.     }
  47. }
  48. class Rece implements Runnable {
  49.     private  DatagramSocket socket;
  50.     public Rece(DatagramSocket socket) {
  51.         this.socket = socket;
  52.     }
  53.     @Override
  54.     public void run() {
  55.         try {
  56.             while(true) {
  57.                 byte[] buff = new byte[1024];
  58.                 DatagramPacket packet = new DatagramPacket(buff,buff.length);
  59.                 socket.receive(packet);
  60.                 String ip = packet.getAddress().getHostAddress();
  61.                 String data = new String(packet.getData(),0,packet.getLength());
  62.                 if(“bye”.equals(data)) {
  63.                     System.out.println(ip+“Already left”);
  64.                     continue;
  65.                 }
  66.                 System.out.println(ip+“Say”+data);
  67.             }
  68.         } catch (IOException e) {
  69.             e.printStackTrace();
  70.         }
  71.     }
  72. }
  73. public class ChatDemo {
  74.     /**
  75. *can be continuously sent to 192.168.168.106:10001
  76. *Send to port 10001 of the receiver, the recipient needs to be accepted at port 10001
  77.      */
  78.     public static void main(String args[]) throws SocketException {
  79.         DatagramSocket sendSocket = new DatagramSocket();
  80.         DatagramSocket reveSocket = new DatagramSocket(10001);
  81.         new Thread(new Send(sendSocket)).start();
  82.         new Thread(new Rece(reveSocket)).start();
  83.     }
  84. }

Instructions

I have two computers here

One IP: 192.168.168.107 MAC

A computer: 192.168.168.106 Windows

The code above is the code of MAC, that is, 192.168.168.107 continuously sends data to the port of 192.168.168.106

192.168.168.106 received at 10001

MAC’s IDEA console sends data and Enter the car

Windows Idea Console Receive Data

ChatDemo2.java

  1. package udp;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.net.*;
  6. /**
  7.  *
  8.  *
  9. *Writing a chat tool
  10. *There is a data part, and the data sends data part
  11. *These two are not performed at the same time
  12. *requires multi -threaded technology
  13. *A thread control collection, a thread control sending
  14.  *
  15. *Because it is inconsistent with the collection and mobility, two methods must be defined
  16. *and these two methods need to be encapsulated into different categories
  17.  *
  18. *@author words 8
  19. *@date 2017/12/6 PM 8:25
  20.  */
  21. class Send2 implements Runnable {
  22.     private MulticastSocket socket;
  23.     public Send2(MulticastSocket socket) {
  24.         this.socket = socket;
  25.     }
  26.     @Override
  27.     public void run() {
  28.         try {
  29.             BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
  30.             InetAddress group = InetAddress.getByName(“228.5.6.7”);
  31.             socket.joinGroup(group);
  32.             String line = null;
  33.             while((line = reader.readLine())!= null) {
  34.                 byte[] buff = line.getBytes();
  35.                 DatagramPacket packet = new DatagramPacket(buff,buff.length,group,6789);
  36.                 socket.send(packet);
  37.                 if(“bey”.equals(line)) {
  38.                     break;
  39.                 }
  40.             }
  41.             socket.close();
  42.         } catch (IOException e) {
  43.             throw new RuntimeException(“Send end failure”);
  44.         }
  45.     }
  46. }
  47. class Rece2 implements Runnable {
  48.     private  MulticastSocket socket;
  49.     public Rece2(MulticastSocket socket) {
  50.         this.socket = socket;
  51.     }
  52.     @Override
  53.     public void run() {
  54.         try {
  55.             byte[] buff = new byte[1024];
  56.             InetAddress group = InetAddress.getByName(“228.5.6.7”);
  57.             socket.joinGroup(group);
  58.             while(true) {
  59.                 DatagramPacket packet = new DatagramPacket(buff,buff.length);
  60.                 socket.receive(packet);
  61.                 String data = new String(packet.getData(),0,packet.getLength());
  62.                 String ip = packet.getAddress().getHostAddress();
  63.                 if(“bye”.equals(data)) {
  64.                     System.out.println(ip+“Leave”);
  65.                     continue;
  66.                 }
  67.                 System.out.println(“ip:”+ip+“Say:”+data);
  68.             }
  69.         } catch (IOException e) {
  70.             throw new RuntimeException(“Accepting end failure”);
  71.         }
  72.     }
  73. }
  74. public class ChatDemo2 {
  75.     public static void main(String args[]) throws IOException {
  76.         MulticastSocket sendSocket = new MulticastSocket();
  77.         MulticastSocket receSocket = new MulticastSocket(6789);
  78.         new Thread(new Send2(sendSocket)).start();
  79.         new Thread(new Rece2(receSocket)).start();
  80.     }
  81. }

Instructions

or two -day machine, run the code above. A group with an IP of 228.5.6.7 is added to receive data on port 6789.

Effect chart

MAC’s IDEA console

Windows Idea console

Radio

ChatDemo3.java

  1. package udp;
  2. import java.io.BufferedReader;
  3. import java.io.IOException;
  4. import java.io.InputStreamReader;
  5. import java.net.DatagramPacket;
  6. import java.net.DatagramSocket;
  7. import java.net.InetAddress;
  8. import java.net.SocketException;
  9. /**
  10.  *
  11.  *
  12. *Writing a chat tool
  13. *There is a data part, and the data sends data part
  14. *These two are not performed at the same time
  15. *Need multi -threaded technology
  16. *A thread control collection, a thread control sending
  17.  *
  18. *Because it is inconsistent with the collection and mobility, two methods must be defined
  19. *and these two methods need to be encapsulated into different categories
  20.  *
  21. *@author words 10
  22. *@date 2017/12/6 PM 8:25
  23.  */
  24. class Send3 implements Runnable {
  25.     private DatagramSocket socket;
  26.     public Send3(DatagramSocket socket) {
  27.         this.socket = socket;
  28.     }
  29.     @Override
  30.     public void run() {
  31.         try {
  32.             BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in));
  33.             String line = null;
  34.             while((line = bufferedReader.readLine()) != null) {
  35.                 byte[] buff = line.getBytes();
  36.                 DatagramPacket packet = new DatagramPacket(buff,buff.length, InetAddress.getByName(“192.168.168.255”),10001);
  37.                 socket.send(packet);
  38.                 if(“bye”.equals(line)) {
  39.                     break;
  40.                 }
  41.             }
  42.             socket.close();
  43.         } catch (IOException e) {
  44.             e.printStackTrace();
  45.         }
  46.     }
  47. }
  48. class Rece3 implements Runnable {
  49.     private  DatagramSocket socket;
  50.     public Rece3(DatagramSocket socket) {
  51.         this.socket = socket;
  52.     }
  53.     @Override
  54.     public void run() {
  55.         try {
  56.             while(true) {
  57.                 byte[] buff = new byte[1024];
  58.                 DatagramPacket packet = new DatagramPacket(buff,buff.length);
  59.                 socket.receive(packet);
  60.                 String ip = packet.getAddress().getHostAddress();
  61.                 String data = new String(packet.getData(),0,packet.getLength());
  62.                 if(“bye”.equals(data)) {
  63.                     System.out.println(ip+“Leave”);
  64.                 }
  65.                 System.out.println(ip+“Say”+data);
  66.             }
  67.         } catch (IOException e) {
  68.             e.printStackTrace();
  69.         }
  70.     }
  71. }
  72. public class ChatDemo3 {
  73.     public static void main(String args[]) throws SocketException {
  74.         DatagramSocket sendSocket = new DatagramSocket();
  75.         DatagramSocket reveSocket = new DatagramSocket(10001);
  76.         new Thread(new Send3(sendSocket)).start();
  77.         new Thread(new Rece3(reveSocket)).start();
  78.     }
  79. }

Instructions

Broadcasting is better to understand, my LAN network address here is 192.168.168.0

So the IP is 192.168.168.1 -192.168.168.254 is an effective IP address in this local area network

192.168.168.255 is called the broadcast address. As long as the broadcast address is sent, everyone in the local area network can receive it.

Running results

MAC version of Idea’s console

Windows version of IDEA’s console

source

Related Posts

Android learning notes (1) Rayfong

CCPC-Wannafly Winter Camp Day1 (DIV2, Once) E flow flow (tree-shaped DP)

GreenPlum Database Single Single Single Deployment

Section 14.7 Python simulation browser access to implement HTTP message compression transmission

[Unity] Create the project environment with githubdesktop management GIT code installation process FMJ

Random Posts

Spring Boot timing task

Uniapp uniuni-list-item Click event invalid

[Oracle] Relevant knowledge of the trigger

Black Horse Programmer —— [Java Basic Article] Language Basics — Keywords, identifiers, annotations, constants and variables and operators

POJ 2115-C LOOOOOPS-Expand the Euclidean Algorithm