<!--Synmanage -->
<bean id="syncManager" class="com.moto.sqm.util.SyncManager"
init-method="run">
<property name="group_ip">
<value>${groupip}</value>
</property>
<property name="group_port">
<value>${groupport}</value>
</property>
</bean>
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.InetAddress;
import java.net.MulticastSocket;
import java.net.UnknownHostException;
import javax.swing.JOptionPane;
public class SyncManager {
private String group_ip;
private int group_port;
public void setGroup_ip(String group_ip) {
this.group_ip = group_ip;
}
public void setGroup_port(int group_port) {
this.group_port = group_port;
}
private MulticastSocket multicastSocket;
/*
* public void run() { System.out.println("server start......."); try {
* InetAddress group = InetAddress.getByName(group_ip); multicastSocket =
* new MulticastSocket(group_port); multicastSocket.joinGroup(group); byte[]
* data = new byte[50]; // 鏈~婊$┖闂翠細琚?濉厖锛屽鏋滄暟鎹暱搴﹁秴鍑烘暟缁勫垯瓒呭嚭鐨勬暟鎹蹇界暐 DatagramPacket
* packet = new DatagramPacket(data, data.length); } catch (Exception e) {
* e.printStackTrace(); return; }
*
* System.out.println("sync manager listen on " + group_ip + ":" +
* group_port + " succ ][][][][][");
*
* }
*
* public void send_notify_msg(String msg) { DatagramPacket packet = new
* DatagramPacket(msg.getBytes(), msg.length()); try {
* multicastSocket.send(packet); } catch (IOException e) {
* e.printStackTrace(); }
*
* }
*/
public void run() {
try {
multicastSocket = new MulticastSocket();
} catch (IOException e) {
e.printStackTrace();
}
}
public void send_notify_msg(String msg) {
try {
byte[] data = msg.getBytes();
InetAddress group = InetAddress.getByName(group_ip);
DatagramPacket packet = new DatagramPacket(data, data.length,
group, group_port);
multicastSocket.send(packet);
System.out.println("send ok");
// Thread.sleep(1000);
} catch (IOException ex) {
// JOptionPane.showMessageDialog(null, "multicast error");
ex.printStackTrace();
}
}
}