java 多网卡绑定例程

单播:

 

DatagramSocket s = new DatagramSocket(0, InetAddress
				.getByName("192.168.29.1"));
		DatagramPacket p = new DatagramPacket(data, data.length, InetAddress
				.getByName("192.168.29.255"), 32000);
		s.send(p);

 

组播:

MulticastSocket s = new MulticastSocket();
		s.setNetworkInterface(NetworkInterface.getByInetAddress(InetAddress
				.getByName("192.168.29.1")));
		s.setTimeToLive(32);
		DatagramPacket pkt = new DatagramPacket(data, data.length, InetAddress
				.getByName("225.1.1.1"), 32000);
		s.send(pkt);
 

你可能感兴趣的:(java)