Java 给飞秋发送消息

来源:互联网 发布:淘宝刷单处罚新规则 编辑:程序博客网 时间:2024/05/29 10:41

UDP面向无连接,给飞秋发送消息

[java] view plain copy
 在CODE上查看代码片派生到我的代码片
  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. }  

0 0