JAVA實現飛秋髮送報文消息

UDP面向無連接,給飛秋髮送消息

[java] view plain copy
  1. package com.wxh.day1017;  
  2. //給飛秋髮送消息  
  3. import java.io.*;  
  4. import java.net.*;  
  5. public class Test {  
  6.       
  7.     public static void main(String[] args) throws IOException {  
  8.         //飛秋的數據格式  
  9.         String str="1:100:Jack:dell:32:hello 你好啊";  
  10.         byte[] array=str.getBytes();  
  11.         //發送的管道  
  12.         DatagramSocket ds=new DatagramSocket();  
  13.         //數據包  
  14.         DatagramPacket dp=new DatagramPacket(array, array.length,InetAddress.getByName("125.220.70.16"),2425);  
  15.         //ds.send(dp);  
  16.         while(true){  
  17.             ds.send(dp);  
  18.             try {  
  19.                 Thread.sleep(1000);  
  20.             } catch (InterruptedException e) {  
  21.                 e.printStackTrace();  
  22.             }  
  23.         }  
  24.           
  25.     }  
  26.   
  27. }  
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章