package qdcl.base.module.ipmsg;
import java.io.IOException;
import java.net.DatagramPacket;
import java.net.DatagramSocket;
import java.net.InetAddress;
import java.net.SocketException;
import java.net.UnknownHostException;
import java.util.Date;
public class IpMSG {
/*========== Constant Value ==========*/
public static final long IPMSG_COMMASK = 0x000000ff;
public static final long IPMSG_OPTMASK = 0xffffff00;
public static final long IPMSG_NOOPERATION = 0x00000000;
public static final long IPMSG_BR_ENTRY = 0x00000001;
public static final long IPMSG_BR_EXIT = 0x00000002;
public static final long IPMSG_ANSENTRY = 0x00000003;
public static final long IPMSG_BR_ABSENCE = 0x00000004;
public static final long IPMSG_BR_ISGETLIST = 0x00000018;
public static final long IPMSG_OKGETLIST = 0x00000015;
public static final long IPMSG_GETLIST = 0x00000016;
public static final long IPMSG_ANSLIST = 0x00000017;
public static final long IPMSG_SENDMSG = 0x00000020;
public static final long IPMSG_RECVMSG = 0x00000021;
public static final long IPMSG_READMSG = 0x00000030;
public static final long IPMSG_DELMSG = 0x00000031;
public static final long IPMSG_GETINFO = 0x00000040;
public static final long IPMSG_SENDINFO = 0x00000041;
// other opt
public static final long IPMSG_ABSENCEOPT = 0x00000100;
public static final long IPMSG_SERVEROPT = 0x00000200;
public static final long IPMSG_DIALUPOPT = 0x00010000;
// send opt
public static final long IPMSG_SENDCHECKOPT = 0x00000100;
public static final long IPMSG_SECRETOPT = 0x00000200;
public static final long IPMSG_BROADCASTOPT = 0x00000400;
public static final long IPMSG_MULTICASTOPT = 0x00000800;
public static final long IPMSG_NOPOPUPOPT = 0x00001000;
public static final long IPMSG_AUTORETOPT = 0x00002000;
public static final long IPMSG_RETRYOPT = 0x00004000;
public static final long IPMSG_PASSWORDOPT = 0x00008000;
public static final long IPMSG_NOLOGOPT = 0x00020000;
public static final long IPMSG_NEWMUTIOPT = 0x00040000;
public static final int MAXBUF = 8192;
public static void main(String[] args) {
DatagramSocket socket;
InetAddress address;
long IPMSG_SENDMSG = 0x00000020;
String SENDER = "王国强";
String HOST = "11.66.244.166";
String MSG_CONTENT = "真能调用飞鸽来。。。。。。";
try {
socket = new DatagramSocket();
address = InetAddress.getByName("11.66.244.166");// 发送给消息的地址
/**
* IPMSG收发数据包的格式(一行):
*
* version(IPMSG版本):no(消息编号,可以用系统时间):user(发送消息的用户名):
* host(发送消息的主机名):command(上述 Command 常量,可以用 | 组合多个值):
* msg(消息内容)
*
*/
byte[] buffer = ("1:" + new Date().getTime() + ":" + SENDER + ":"
+ HOST + ":" + IPMSG_SENDMSG + ":" + MSG_CONTENT)
.getBytes();
DatagramPacket packet = new DatagramPacket(buffer, buffer.length,
address, 2425);
socket.send(packet); // 发送报文
packet = new DatagramPacket(buffer, buffer.length);
socket.receive(packet);// 接收回应
String message = new String(packet.getData()); // 得到报文信息
System.out.println(message); // 显示对方返回的信息
} catch (UnknownHostException e) {
e.printStackTrace();
} catch (SocketException e) {
e.printStackTrace();
}
catch (IOException e) {
e.printStackTrace();
}
}
}
java 调用飞鸽传书源码
最新推荐文章于 2024-10-16 16:06:30 发布