package cn.socket.udp;
import java.io.IOException; import java.net.DatagramPacket; import java.net.DatagramSocket; import java.net.InetAddress; import java.net.SocketException; import java.net.UnknownHostException; public class sendUDP extends Thread{ /**
* @param args */ public static void main(String[] args) { for(int i=0;i<5;i++){ sendUDP udpTestUDP=new sendUDP(); udpTestUDP.start(); } } public void run(){ DatagramSocket gramSocket= null; try { gramSocket = new DatagramSocket(); } catch (SocketException e) { e.printStackTrace(); } String info="1111111:22.36-25.2-20110802221144-12,22.9-32.89-20100102112244-45,36.25-56.25-20101424445544-0"; try { DatagramPacket packet= new DatagramPacket(info.getBytes(),info.length(),InetAddress.getByName("127.0.0.1"),10001); gramSocket.send(packet); gramSocket.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); } } } |
|