1. import
2.
3. import
4. import
5.
6. public class
7.
8. /** Server name */
9. public static final String SERVER_NAME = "localhost";
10. /** Server port */
11. public static final int SERVER_PORT = 5222; // as you can see in Admin
12. // Console properties
13.
14. /** Client name - for login */
15. private final
16. /** Client password - for login*/
17. private final
18. /** Client color - for writing in color */
19. private final
20. /** Chat friend */
21. private final
22.
23. /**
24. * Constrcuts a new SimpleClient
25. * @param clientName0 -
26. * @param clientPassword0 -
27. * @param clientColor0 -
28. * @param friendName0 -
29. */
30. public
31. super();
32. this.clientName = clientName0;
33. this.clientPassword = clientPassword0;
34. this.clientColor = clientColor0;
35. this.friendName = friendName0;
36. }
37.
38. /**
39. * Main process.
40. */
41. public void
42. try
43. this.runImpl();
44. catch
45. "Exception: "
46. }
47.
48. }
49.
50. private void runImpl() throws
51. true;
52.
53. /*
54. * Configuration
55. */
56. final ConnectionConfiguration config = new
57. SimpleClient.SERVER_NAME, SimpleClient.SERVER_PORT);
58. config
59. .setSecurityMode(ConnectionConfiguration.SecurityMode.disabled);
60. false);
61.
62.
63. /*
64. * Open Connection
65. */
66. final XMPPConnection connection = new
67. connection.connect();
68. this.clientName, this.clientPassword);
69.
70. /*
71. * Chat
72. */
73. final MessageListener messageListner = new
74. final Chat chat = connection.getChatManager().createChat(this.friendName, messageListner);
75. final java.util.Date date = new
76. final String msgSent = " [sent by " + this.clientName + ", at " + date.toString() + "]";
77. final Message newMessage = new
78. "Howdy (colored)!"
79. "favoriteColor", this.clientColor);
80. chat.sendMessage(newMessage);
81. "Howdy!"
82.
83. /*
84. * Roster
85. */
86. final
87. // this is already the default Mode but added just for the example
88. Roster
89. .setDefaultSubscriptionMode(Roster.SubscriptionMode.accept_all);
90. this.friendName, "", null);
91.
92. this.presenceStatus(roster, "unknown@someone");
93. this.presenceStatus(roster, this.friendName);
94.
95. final
96. for
97. "RosterEntry "
98. }
99.
100. final RosterListener rosterListener = new
101. roster.addRosterListener(rosterListener);
102.
103. /*
104. * End connection
105. */
106. connection.disconnect();
107. }
108.
109. private void presenceStatus(final
110. final
111. final String response = presence == null ? "Not around"
112. "Presence of '" + user + "': "
113. }
114.
115. /**
116. *
117. * @author some
118. *
119. */
120. private class SimpleMessageListner implements
121. public void
122. "Received message: "
123. + message.getBody());
124. }
125. }
126.
127. /**
128. *
129. * @author some
130. *
131. */
132. private class SimpleRosterListner implements
133. // Ignored events
134. public void
135. }
136.
137. public void
138. }
139.
140. public void
141. }
142.
143. public void
144. "Presence changed: "
145. " "
146. }
147.
148. }
149.
150. }
openFire客户端编程例子
原创
©著作权归作者所有:来自51CTO博客作者mb6459beff599ab的原创作品,请联系作者获取转载授权,否则将追究法律责任
上一篇:Mongodb 地理位置索引
下一篇:Log4j日志配置
提问和评论都可以,用心的回复会被更多人看到
评论
发布评论
相关文章
-
【Networking】Libevent客户端例子
Networking
c/c++ networking libevent -
openfire客户端文件传输学习笔记(一)
o目中需要用到openfire的文件传输,但是客户端使用flex,官方提供的xiff包中并没有封装文件传输的功能,没办法
大数据 网络 xml iphone 文件传输