日韩性视频-久久久蜜桃-www中文字幕-在线中文字幕av-亚洲欧美一区二区三区四区-撸久久-香蕉视频一区-久久无码精品丰满人妻-国产高潮av-激情福利社-日韩av网址大全-国产精品久久999-日本五十路在线-性欧美在线-久久99精品波多结衣一区-男女午夜免费视频-黑人极品ⅴideos精品欧美棵-人人妻人人澡人人爽精品欧美一区-日韩一区在线看-欧美a级在线免费观看

歡迎訪問 生活随笔!

生活随笔

當(dāng)前位置: 首頁 > 编程语言 > java >内容正文

java

java发送ipmsg,[导入]用Java向IPMSG发送消息(转)

發(fā)布時(shí)間:2024/1/1 java 39 豆豆
生活随笔 收集整理的這篇文章主要介紹了 java发送ipmsg,[导入]用Java向IPMSG发送消息(转) 小編覺得挺不錯(cuò)的,現(xiàn)在分享給大家,幫大家做個(gè)參考.

飛鴿傳書(IP Messenger,簡(jiǎn)為IPMsg)是一個(gè)小巧方便的即時(shí)通信軟件,它適合用于局域網(wǎng)內(nèi)甚至廣域網(wǎng)間進(jìn)行實(shí)時(shí)通信和文檔共享。特別是在局域網(wǎng)內(nèi)傳送文件/文件夾的速度非常快!IPMsg 是一款局域網(wǎng)內(nèi)即時(shí)通信軟件, 基于 TCP/IP(UDP).

可運(yùn)行于多種操作平臺(tái)(Win/Mac/UNIX/Java), 并實(shí)現(xiàn)跨平臺(tái)信息交流.

不需要服務(wù)器支持.

支持文件/文件夾的傳送 (2.00版以上)

通訊數(shù)據(jù)采用 RSA/Blofish 加密 (2.00版以上)

十分小巧, 簡(jiǎn)單易用, 而且你可以完全免費(fèi)使用它

目前已有的版本包括: Win32, Win16, MacOS, MacOSX, X11, GTK, GNOME,Java 等, 并且公開源代碼。

本文演示了如何使用Java的net包,向IPMSG客戶端發(fā)送消息。

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收發(fā)數(shù)據(jù)包的格式(一行):

1 version(IPMSG版本):no(消息編號(hào),可以用系統(tǒng)時(shí)間):user(發(fā)送消息的用戶名):host(發(fā)送消息的主機(jī)名):command(上述?Command?常量,可以用?|?組合多個(gè)值):msg(消息內(nèi)容)

示例(向IPMSG發(fā)送消息,需要先打開對(duì)方的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");// 發(fā)送給消息的地址

29

30 /**

31 ???????*?IPMSG收發(fā)數(shù)據(jù)包的格式(一行):

32 ???????*

33 ???????*?version(IPMSG版本):no(消息編號(hào),可以用系統(tǒng)時(shí)間):user(發(fā)送消息的用戶名):

34 ???????*?host(發(fā)送消息的主機(jī)名):command(上述?Command?常量,可以用?|?組合多個(gè)值):

35 ???????*?msg(消息內(nèi)容)

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);?//?發(fā)送報(bào)文

44

45 ??????packet?= new?DatagramPacket(buffer,?buffer.length);

46 ??????socket.receive(packet);//?接收回應(yīng)

47

48 ??????String?message?= new?String(packet.getData());?//?得到報(bào)文信息

49

50 ??????System.out.println(message);?//?顯示對(duì)方返回的信息

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 }

69http://x-spirit.spaces.live.com/Blog/cns!CC0B04AE126337C0!278.entry

總結(jié)

以上是生活随笔為你收集整理的java发送ipmsg,[导入]用Java向IPMSG发送消息(转)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。

如果覺得生活随笔網(wǎng)站內(nèi)容還不錯(cuò),歡迎將生活随笔推薦給好友。