場景
AAA(網絡安全系統) 是認證(Authentication)、授權(Authorization)和計費(Accounting)的簡稱,是網絡安全中進行訪問控制的一種安全管理機制,提供認證、授權和計費三種安全服務。
RADIUS:Remote Authentication Dial In User Service,遠程用戶撥號認證系統由RFC2865,RFC2866定義,是應用最廣泛的AAA協議。AAA是一種管理框架,因此,它可以用多種協議來實現。在實踐中,人們最常使用遠程訪問撥號用戶服務(Remote Authentication Dial In User Service,RADIUS)來實現AAA。對方AAA radius服務器,向我方傳輸用戶上線及相關流量計費信息,我方進行實時接收並展示。而 Radius協議是采用UDP協議作為其傳輸層協議。
使用
發送端
import java.io.IOException;
import java.net.*;
/**
* @Describtion Todo
* @Author yonyong
* @Date 2020/5/11 16:48
* @Version 1.0.0
**/
public class UDPServer {
public static void main(String[] args) throws IOException {
//1、創建udp服務,通過DategramSocket對象;
DatagramSocket ds=new DatagramSocket();
//2、確定數據,並封裝數據到數據包.DatagramPacket(byte[] buf, int length, InetAddress address, int port)
String string = "yonyong 666";
//getBytes(): 使用平台的默認字符集將字符串編碼為 byte 序列,並將結果存儲到一個新的 byte 數組中。
byte[] buf=string.getBytes();
DatagramPacket dp=new DatagramPacket(buf, buf.length, InetAddress.getByName("127.0.0.1"),10000);
//3、通過socket服務,將已有的數據報發送出去,通過send方法。
ds.send(dp);
//4、關閉資源
ds.close();
}
}
接收端
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
/**
* @Describtion Todo
* @Author yonyong
* @Date 2020/5/11 16:53
* @Version 1.0.0
**/
public class UDPClient {
public static void main(String[] args) throws IOException {
DatagramSocket ds=new DatagramSocket(10000);
while(true){
byte[] buf=new byte[1024];
DatagramPacket dp=new DatagramPacket(buf, buf.length);
ds.receive(dp);
String ip=dp.getAddress().getHostAddress();
String data=new String(dp.getData(),0,dp.getLength());
System.out.println(ip+"::"+data);
}
}
}