飞鸽传书(IP Messenger,简为IPMsg)是一个小巧方便的即时通信软件,它适合用于局域网内甚至广域网间进行实时通信和文档共享。特别是在局域网内传送文件/文件夹的速度非常快!
IPMsg 是一款局域网内即时通信软件, 基于 TCP/IP(UDP).
可运行于多种操作平台(Win/Mac/UNIX/Java), 并实现跨平台信息交流.
不需要服务器支持.
支持文件/文件夹的传送 (2.00版以上)
通讯数据采用 RSA/Blofish 加密 (2.00版以上)
十分小巧, 简单易用, 而且你可以完全免费使用它
目前已有的版本包括: Win32, Win16, MacOS, MacOSX, X11, GTK, GNOME,Java 等, 并且公开源代码。
本文演示了如何使用Java的net包,向IPMSG客户端发送消息。
IPMSG Command 常量定义如下:
1 /*========== Constant Value ==========*/
2 public static final long IPMSG_COMMASK = 0x000000ff;
3 public static final long IPMSG_OPTMASK = 0xffffff00;
4 public static final long IPMSG_NOOPERATION = 0x00000000;
5 public static final long IPMSG_BR_ENTRY = 0x00000001;
6 public static final long IPMSG_BR_EXIT = 0x00000002;
7 public static final long IPMSG_ANSENTRY = 0x00000003;
8 public static final long IPMSG_BR_ABSENCE = 0x00000004;
9
10
11
12 public static final long IPMSG_BR_ISGETLIST = 0x00000018;
13 public static final long IPMSG_OKGETLIST = 0x00000015;
14 public static final long IPMSG_GETLIST = 0x00000016;
15 public static final long IPMSG_ANSLIST = 0x00000017;
16
17 public static final long IPMSG_SENDMSG = 0x00000020;
18 public static final long IPMSG_RECVMSG = 0x00000021;
19
20 public static final long IPMSG_READMSG = 0x00000030;
21 public static final long IPMSG_DELMSG = 0x00000031;
22
23 public static final long IPMSG_GETINFO = 0x00000040;
24 public static final long IPMSG_SENDINFO = 0x00000041;
25
26 // other opt
27 public static final long IPMSG_ABSENCEOPT = 0x00000100;
28 public static final long IPMSG_SERVEROPT = 0x00000200;
29 public static final long IPMSG_DIALUPOPT = 0x00010000;
30
31 // send opt
32 public static final long IPMSG_SENDCHECKOPT = 0x00000100;
33 public static final long IPMSG_SECRETOPT = 0x00000200;
34 public static final long IPMSG_BROADCASTOPT = 0x00000400;
35 public static final long IPMSG_MULTICASTOPT = 0x00000800;
36 public static final long IPMSG_NOPOPUPOPT = 0x00001000;
37 public static final long IPMSG_AUTORETOPT = 0x00002000;
38 public static final long IPMSG_RETRYOPT = 0x00004000;
39 public static final long IPMSG_PASSWORDOPT = 0x00008000;
40 public static final long IPMSG_NOLOGOPT = 0x00020000;
41 public static final long IPMSG_NEWMUTIOPT = 0x00040000;
42
43 public static final int MAXBUF = 8192;
44 /*========== end ==========*/
IPMSG收发数据包的格式(一行):
1 version(IPMSG版本):no(消息编号,可以用系统时间):user(发送消息的用户名):host(发送消息的主机名):command(上述 Command 常量,可以用 | 组合多个值):msg(消息内容)
示例(向IPMSG发送消息,需要先打开对方的IPMSG):
1 import java.io.IOException;
2 import java.net.DatagramPacket;
3 import java.net.DatagramSocket;
4 import java.net.InetAddress;
5 import java.net.SocketException;
6 import java.net.UnknownHostException;
7 import java.util.Date;
8
9 /**
10 * @author 乱 7 8 糟 http://blog.csdn.net/comstep
11 */
12 public class TestIPMSG
13 {
14 public static void main(String[] args)
15 {
16 DatagramSocket socket;
17 InetAddress address;
18
19 long IPMSG_SENDMSG = 0x00000020;
20
21 String SENDER = "乱 7 8 糟";
22 String HOST = "Localhost";
23 String MSG_CONTENT = "Hello World!";
24
25 try
26 {
27 socket = new DatagramSocket();
28 address = InetAddress.getByName("192.168.1.20");// 发送给消息的地址
29
30 /**
31 * IPMSG收发数据包的格式(一行):
32 *
33 * version(IPMSG版本):no(消息编号,可以用系统时间):user(发送消息的用户名):
34 * host(发送消息的主机名):command(上述 Command 常量,可以用 | 组合多个值):
35 * msg(消息内容)
36 *
37 */
38 byte[] buffer = ("1:" + new Date().getTime() + ":" + SENDER + ":" + HOST
39 + ":" + IPMSG_SENDMSG + ":" + MSG_CONTENT).getBytes();
40
41 DatagramPacket packet = new DatagramPacket(buffer, buffer.length,
42 address, 2425);
43 socket.send(packet); // 发送报文
44
45 packet = new DatagramPacket(buffer, buffer.length);
46 socket.receive(packet);// 接收回应
47
48 String message = new String(packet.getData()); // 得到报文信息
49
50 System.out.println(message); // 显示对方返回的信息
51 }
52 catch (UnknownHostException e)
53 {
54 e.printStackTrace();
55 }
56 catch (SocketException e)
57 {
58 e.printStackTrace();
59 }
60
61 catch (IOException e)
62 {
63 e.printStackTrace();
64 }
65
66 }
67
68 }
IPMsg 是一款局域网内即时通信软件, 基于 TCP/IP(UDP).
可运行于多种操作平台(Win/Mac/UNIX/Java), 并实现跨平台信息交流.
不需要服务器支持.
支持文件/文件夹的传送 (2.00版以上)
通讯数据采用 RSA/Blofish 加密 (2.00版以上)
十分小巧, 简单易用, 而且你可以完全免费使用它
目前已有的版本包括: Win32, Win16, MacOS, MacOSX, X11, GTK, GNOME,Java 等, 并且公开源代码。
本文演示了如何使用Java的net包,向IPMSG客户端发送消息。
IPMSG Command 常量定义如下:
1 /*========== Constant Value ==========*/
2 public static final long IPMSG_COMMASK = 0x000000ff;
3 public static final long IPMSG_OPTMASK = 0xffffff00;
4 public static final long IPMSG_NOOPERATION = 0x00000000;
5 public static final long IPMSG_BR_ENTRY = 0x00000001;
6 public static final long IPMSG_BR_EXIT = 0x00000002;
7 public static final long IPMSG_ANSENTRY = 0x00000003;
8 public static final long IPMSG_BR_ABSENCE = 0x00000004;
9
10
11
12 public static final long IPMSG_BR_ISGETLIST = 0x00000018;
13 public static final long IPMSG_OKGETLIST = 0x00000015;
14 public static final long IPMSG_GETLIST = 0x00000016;
15 public static final long IPMSG_ANSLIST = 0x00000017;
16
17 public static final long IPMSG_SENDMSG = 0x00000020;
18 public static final long IPMSG_RECVMSG = 0x00000021;
19
20 public static final long IPMSG_READMSG = 0x00000030;
21 public static final long IPMSG_DELMSG = 0x00000031;
22
23 public static final long IPMSG_GETINFO = 0x00000040;
24 public static final long IPMSG_SENDINFO = 0x00000041;
25
26 // other opt
27 public static final long IPMSG_ABSENCEOPT = 0x00000100;
28 public static final long IPMSG_SERVEROPT = 0x00000200;
29 public static final long IPMSG_DIALUPOPT = 0x00010000;
30
31 // send opt
32 public static final long IPMSG_SENDCHECKOPT = 0x00000100;
33 public static final long IPMSG_SECRETOPT = 0x00000200;
34 public static final long IPMSG_BROADCASTOPT = 0x00000400;
35 public static final long IPMSG_MULTICASTOPT = 0x00000800;
36 public static final long IPMSG_NOPOPUPOPT = 0x00001000;
37 public static final long IPMSG_AUTORETOPT = 0x00002000;
38 public static final long IPMSG_RETRYOPT = 0x00004000;
39 public static final long IPMSG_PASSWORDOPT = 0x00008000;
40 public static final long IPMSG_NOLOGOPT = 0x00020000;
41 public static final long IPMSG_NEWMUTIOPT = 0x00040000;
42
43 public static final int MAXBUF = 8192;
44 /*========== end ==========*/
IPMSG收发数据包的格式(一行):
1 version(IPMSG版本):no(消息编号,可以用系统时间):user(发送消息的用户名):host(发送消息的主机名):command(上述 Command 常量,可以用 | 组合多个值):msg(消息内容)
示例(向IPMSG发送消息,需要先打开对方的IPMSG):
1 import java.io.IOException;
2 import java.net.DatagramPacket;
3 import java.net.DatagramSocket;
4 import java.net.InetAddress;
5 import java.net.SocketException;
6 import java.net.UnknownHostException;
7 import java.util.Date;
8
9 /**
10 * @author 乱 7 8 糟 http://blog.csdn.net/comstep
11 */
12 public class TestIPMSG
13 {
14 public static void main(String[] args)
15 {
16 DatagramSocket socket;
17 InetAddress address;
18
19 long IPMSG_SENDMSG = 0x00000020;
20
21 String SENDER = "乱 7 8 糟";
22 String HOST = "Localhost";
23 String MSG_CONTENT = "Hello World!";
24
25 try
26 {
27 socket = new DatagramSocket();
28 address = InetAddress.getByName("192.168.1.20");// 发送给消息的地址
29
30 /**
31 * IPMSG收发数据包的格式(一行):
32 *
33 * version(IPMSG版本):no(消息编号,可以用系统时间):user(发送消息的用户名):
34 * host(发送消息的主机名):command(上述 Command 常量,可以用 | 组合多个值):
35 * msg(消息内容)
36 *
37 */
38 byte[] buffer = ("1:" + new Date().getTime() + ":" + SENDER + ":" + HOST
39 + ":" + IPMSG_SENDMSG + ":" + MSG_CONTENT).getBytes();
40
41 DatagramPacket packet = new DatagramPacket(buffer, buffer.length,
42 address, 2425);
43 socket.send(packet); // 发送报文
44
45 packet = new DatagramPacket(buffer, buffer.length);
46 socket.receive(packet);// 接收回应
47
48 String message = new String(packet.getData()); // 得到报文信息
49
50 System.out.println(message); // 显示对方返回的信息
51 }
52 catch (UnknownHostException e)
53 {
54 e.printStackTrace();
55 }
56 catch (SocketException e)
57 {
58 e.printStackTrace();
59 }
60
61 catch (IOException e)
62 {
63 e.printStackTrace();
64 }
65
66 }
67
68 }