- 浏览: 916779 次
- 性别:
- 来自: 上海
文章分类
- 全部博客 (263)
- J2EE (9)
- Spring (11)
- Hibernate (11)
- Struts (5)
- opensource (19)
- Hadoop (28)
- 架构设计 (8)
- 企业应用 (10)
- SNMP (8)
- SSO (4)
- webservice (11)
- RPC (2)
- 编程语言 (0)
- Java (30)
- Javascript (5)
- NoSQL (11)
- 数据库 (0)
- oracle (8)
- MySQL (3)
- web (1)
- Android (2)
- Linux (15)
- 软件工具 (15)
- 项目构建 (11)
- 测试工具 (2)
- Exception (19)
- 杂谈 (4)
- Groovy (5)
- Nodejs (1)
- MacOSX (4)
最新评论
-
fighhin:
decode(BinaryBitmap,java.util.M ...
条形码/二维码之开源利器ZXing图文介绍 -
u013489005:
追问:楼主,请问有中文文档么?我的邮箱是frankgray@s ...
Java表达式计算引擎:Expr4J -
u013489005:
感谢博主 需要引入的包是import java.io.*;im ...
Java表达式计算引擎:Expr4J -
calosteward:
感谢楼主分享。。 Zxing 我听说过的。__________ ...
条形码/二维码之开源利器ZXing图文介绍 -
u013810758:
judasqiqi 写道感谢楼主!想请问楼主一下这个生成的图片 ...
Java实现二维码QRCode的编码和解码
blog迁移至 :http://www.micmiu.com
JML是Java实现即时通讯软件MSN的lib包,目前支持的协议为MSNP8-MSNP15。
JML的官网:http://sourceforge.net/projects/java-jml/
【一】、基本介绍
附件提供测试代码和lib文件:
- msn demo代码:my_demo_code.zip
- lib包:jml-1.0b4.jar
- 官方example文件:example.zip
JML的lib还依赖的其他第三方lib包:
- cindy.jar
- commons-logging.jar
- httpcore.jar
- 第三方lib包下载:第三方lib.zip
【二】、DEMO代码
简单实现了MSN收发消息、好友添加等等基本功能。
MyJmsnClient.java
package michael.msn.jml; import java.util.Scanner; import net.sf.jml.MsnContact; import net.sf.jml.MsnMessenger; import net.sf.jml.MsnProtocol; import net.sf.jml.MsnUserStatus; import net.sf.jml.impl.MsnMessengerFactory; import org.apache.log4j.PropertyConfigurator; /** * @author michael * */ public class MyJmsnClient { private String msnEmail; private String msnPassword; private MsnMessenger msn; /** * @param msnEmail * @param msnPassword */ public MyJmsnClient(String msnEmail, String msnPassword) { this.msnEmail = msnEmail; this.msnPassword = msnPassword; } /** * 启动 */ public void start() { // 创建MsnMessenger msn = MsnMessengerFactory.createMsnMessenger(msnEmail, msnPassword); // 设置登录协议 MSNP15 可以发送离线消息 msn.setSupportedProtocol(new MsnProtocol[] { MsnProtocol.MSNP15 }); // 设置用户状态 msn.getOwner().setInitStatus(MsnUserStatus.ONLINE); // 注册事件监听 msn.addListener(new MyJmsnSimpleAdapter()); msn.login();// 登录 } /** * msn logout */ public void stop() { msn.logout(); } /** * 给所有的人发消息 * @param msg */ public void sendAllMsg(String msg) { MsnContact[] contactList = msn.getContactList().getContacts(); for (MsnContact con : contactList) { msn.sendText(con.getEmail(), msg); } } /** * @param args */ public static void main(String[] args) { PropertyConfigurator.configure(MyJmsnClient.class .getResource("/log4j.properties")); MyJmsnClient client = new MyJmsnClient("yourmsnemail", "yourpassword"); System.out.println(" MyJmsnClient start ..."); client.start(); try { Thread.sleep(5000); } catch (Exception e) { e.printStackTrace(); } //获取控制台输入的信息发送给所有的好友 Scanner input = new Scanner(System.in); while (input.hasNext()) { String s = input.next(); if ("quit".equals(s)) { System.out.println(" MSN exit by quit"); client.stop(); break; } else { client.sendAllMsg(s); } } System.out.println("====================="); } }
MyJmsnSimpleAdapter.java
package michael.msn.jml; import net.sf.jml.MsnContact; import net.sf.jml.MsnFileTransfer; import net.sf.jml.MsnList; import net.sf.jml.MsnMessenger; import net.sf.jml.MsnSwitchboard; import net.sf.jml.event.MsnAdapter; import net.sf.jml.message.MsnControlMessage; import net.sf.jml.message.MsnEmailInitEmailData; import net.sf.jml.message.MsnInstantMessage; import org.apache.log4j.Logger; /** * 实现了一个简单的MsnAdapter * @author michael * */ public class MyJmsnSimpleAdapter extends MsnAdapter { private static final Logger logger = Logger .getLogger(MyJmsnSimpleAdapter.class); /** * @see net.sf.jml.event.MsnAdapter#contactAddCompleted(net.sf.jml.MsnMessenger, * net.sf.jml.MsnContact, net.sf.jml.MsnList) * @param pMessenger * @param pContact * @param pList */ @Override public void contactAddCompleted(MsnMessenger pMessenger, MsnContact pContact, MsnList pList) { super.contactAddCompleted(pMessenger, pContact, pList); try { pMessenger.sendText(pContact.getEmail(), pContact.getFriendlyName() + " 你好,已经加为好友"); } catch (Exception e) { logger.error("contactAddCompleted sendText error", e); } } /** * @see net.sf.jml.event.MsnAdapter#contactAddedMe(net.sf.jml.MsnMessenger, * net.sf.jml.MsnContact) * @param pMessenger * @param pContact */ @Override public void contactAddedMe(MsnMessenger pMessenger, MsnContact pContact) { super.contactAddedMe(pMessenger, pContact); logger.info("user: " + pContact.getEmail() + " Add me."); try { pMessenger.addFriend(pContact.getEmail(), pContact .getFriendlyName()); } catch (Exception e) { logger.error("addFriend error:", e); } } /** * @see net.sf.jml.event.MsnAdapter#contactListInitCompleted(net.sf.jml.MsnMessenger) * @param pMessenger */ @Override public void contactListInitCompleted(MsnMessenger pMessenger) { super.contactListInitCompleted(pMessenger); MsnContact[] cons = pMessenger.getContactList().getContactsInList( MsnList.AL); logger.info("你的联系人数量=" + cons.length); for (MsnContact con : cons) { logger.info("联系人:" + con.getEmail().getEmailAddress() + " 状态:" + con.getStatus().getDisplayStatus()); } } /** * @see net.sf.jml.event.MsnAdapter#contactListSyncCompleted(net.sf.jml.MsnMessenger) * @param pMessenger */ @Override public void contactListSyncCompleted(MsnMessenger pMessenger) { super.contactListSyncCompleted(pMessenger); logger.info("MSN contactListSyncCompleted."); } /** * @see net.sf.jml.event.MsnAdapter#contactRemoveCompleted(net.sf.jml.MsnMessenger, * net.sf.jml.MsnContact, net.sf.jml.MsnList) * @param pMessenger * @param pContact * @param pList */ @Override public void contactRemoveCompleted(MsnMessenger pMessenger, MsnContact pContact, MsnList pList) { super.contactRemoveCompleted(pMessenger, pContact, pList); logger.info("user: " + pContact.getEmail() + " Remove Completed."); } /** * @see net.sf.jml.event.MsnAdapter#contactRemovedMe(net.sf.jml.MsnMessenger, * net.sf.jml.MsnContact) * @param pMessenger * @param pContact */ @Override public void contactRemovedMe(MsnMessenger pMessenger, MsnContact pContact) { super.contactRemovedMe(pMessenger, pContact); logger.info("user: " + pContact.getEmail() + " Remove me."); } /** * @see net.sf.jml.event.MsnAdapter#controlMessageReceived(net.sf.jml.MsnSwitchboard, * net.sf.jml.message.MsnControlMessage, net.sf.jml.MsnContact) * @param pSwitchboard * @param pMessage * @param pContact */ @Override public void controlMessageReceived(MsnSwitchboard pSwitchboard, MsnControlMessage pMessage, MsnContact pContact) { super.controlMessageReceived(pSwitchboard, pMessage, pContact); logger.info(pContact.getFriendlyName() + " 正在输入文字......"); } /** * @see net.sf.jml.event.MsnAdapter#exceptionCaught(net.sf.jml.MsnMessenger, * java.lang.Throwable) * @param pMessenger * @param pThrowable */ @Override public void exceptionCaught(MsnMessenger pMessenger, Throwable pThrowable) { super.exceptionCaught(pMessenger, pThrowable); logger.error("exceptionCaught :", pThrowable); } /** * @see net.sf.jml.event.MsnAdapter#fileTransferRequestReceived(net.sf.jml.MsnFileTransfer) * @param pTransfer */ @Override public void fileTransferRequestReceived(MsnFileTransfer pTransfer) { super.fileTransferRequestReceived(pTransfer); logger.info("receive fileTransferRequest from " + pTransfer.getContact().getDisplayName()); } /** * @see net.sf.jml.event.MsnAdapter#initialEmailDataReceived(net.sf.jml.MsnSwitchboard, * net.sf.jml.message.MsnEmailInitEmailData, net.sf.jml.MsnContact) * @param pSwitchboard * @param pMessage * @param pContact */ @Override public void initialEmailDataReceived(MsnSwitchboard pSwitchboard, MsnEmailInitEmailData pMessage, MsnContact pContact) { super.initialEmailDataReceived(pSwitchboard, pMessage, pContact); logger.info("receive email from " + pContact.getDisplayName()); } /** * @see net.sf.jml.event.MsnAdapter#instantMessageReceived(net.sf.jml.MsnSwitchboard, * net.sf.jml.message.MsnInstantMessage, net.sf.jml.MsnContact) * @param pSwitchboard * @param pMessage * @param pContact */ @Override public void instantMessageReceived(MsnSwitchboard pSwitchboard, MsnInstantMessage pMessage, MsnContact pContact) { super.instantMessageReceived(pSwitchboard, pMessage, pContact); logger.info("received from: " + pContact.getDisplayName() + " with msg: " + pMessage.getContent()); try { MsnInstantMessage msg = new MsnInstantMessage(); msg.setContent("你好!我是机器人Michael,请勿回复消息。" + "\r\n你可以访问我的blog http://sjsky.iteye.com"); msg.setFontRGBColor(255); pSwitchboard.sendMessage(msg);// 发送信息 pSwitchboard.close();// 关闭对话框 } catch (Exception e) { e.printStackTrace(); } } /** * @see net.sf.jml.event.MsnAdapter#loginCompleted(net.sf.jml.MsnMessenger) * @param pMessenger */ @Override public void loginCompleted(MsnMessenger pMessenger) { super.loginCompleted(pMessenger); logger.info("MSN login success with ID=" + pMessenger.getOwner().getEmail()); } /** * @see net.sf.jml.event.MsnAdapter#logout(net.sf.jml.MsnMessenger) * @param pMessenger */ @Override public void logout(MsnMessenger pMessenger) { super.logout(pMessenger); logger.info("MSN logout with ID=" + pMessenger.getOwner().getEmail()); } /** * @see net.sf.jml.event.MsnAdapter#offlineMessageReceived(java.lang.String, * java.lang.String, java.lang.String, net.sf.jml.MsnContact) * @param pBody * @param pContentType * @param pEncoding * @param pContact */ @Override public void offlineMessageReceived(String pBody, String pContentType, String pEncoding, MsnContact pContact) { super.offlineMessageReceived(pBody, pContentType, pEncoding, pContact); logger.info("receive offline msg from: " + pContact.getEmail().getEmailAddress() + " msg:" + pContact.getPersonalMessage()); } /** * @see net.sf.jml.event.MsnAdapter#ownerDisplayNameChanged(net.sf.jml.MsnMessenger) * @param pMessenger */ @Override public void ownerDisplayNameChanged(MsnMessenger pMessenger) { super.ownerDisplayNameChanged(pMessenger); logger.info("MSN DisplayName : " + pMessenger.getOwner().getOldDisplayName() + " -> " + pMessenger.getOwner().getDisplayName()); } /** * @see net.sf.jml.event.MsnAdapter#ownerStatusChanged(net.sf.jml.MsnMessenger) * @param pMessenger */ @Override public void ownerStatusChanged(MsnMessenger pMessenger) { super.ownerStatusChanged(pMessenger); logger .info("MSN status :" + pMessenger.getOwner().getOldStatus() .getDisplayStatus() + " -> " + pMessenger.getOwner().getStatus().getDisplayStatus()); } }
-----------------------------------分 ------------------------------------隔
------------------------------------线 --------------------------------------
- jml-1.0b4.jar (315.9 KB)
- 下载次数: 77
- example.zip (11.5 KB)
- 下载次数: 81
- 第三方lib.zip (408.3 KB)
- 下载次数: 125
- my_demo_code.zip (2.9 KB)
- 下载次数: 99
评论
5 楼
ghostwjk
2012-10-31
试了一下,MSNP15报错,官网上好像说是bug,MSNP12没问题。
4 楼
luoaz
2012-05-09
sjsky 写道
luoaz 写道
楼主,根据JML官方说明,好像不支持MSNP15吧,我按照上面的例子跑了下,出现的问题同楼上一样,楼主有遇到这样的问题吗?求回复
我试试吧 我当时没有这样的问题的
楼主你有没有试啊,结果怎么样?会出现301吗?有没有解决办法?
3 楼
sjsky
2012-05-06
luoaz 写道
楼主,根据JML官方说明,好像不支持MSNP15吧,我按照上面的例子跑了下,出现的问题同楼上一样,楼主有遇到这样的问题吗?求回复
我试试吧 我当时没有这样的问题的
2 楼
luoaz
2012-05-04
楼主,根据JML官方说明,好像不支持MSNP15吧,我按照上面的例子跑了下,出现的问题同楼上一样,楼主有遇到这样的问题吗?求回复
1 楼
tywo45
2011-11-15
跑是能跑了,但是报错,不知何故:
MyJmsnClient start ...
2011-11-15 17:59:44,703 [net.sf.jml.net.SocketSession.msgDispatcher] INFO [com.talent.platform.demo.openfire.msn.my.MyJmsnSimpleAdapter] - MSN login success with ID=tanyaowu45@hotmail.com
2011-11-15 17:59:51,343 [net.sf.jml.net.SocketSession.msgDispatcher] ERROR [net.sf.jml.protocol.soap.ContactList] - something wrong!
java.lang.Exception
at net.sf.jml.protocol.soap.ContactList.sendRequest(ContactList.java:276)
at net.sf.jml.protocol.soap.ContactList.sendRequest(ContactList.java:271)
at net.sf.jml.protocol.soap.ContactList.sendRequest(ContactList.java:160)
at net.sf.jml.protocol.soap.ContactList.dispatch(ContactList.java:395)
at net.sf.jml.protocol.incoming.IncomingUSR.messageReceived(IncomingUSR.java:150)
at net.sf.jml.protocol.MsnSession$1.messageReceived(MsnSession.java:107)
at net.sf.jml.net.Session.fireMessageReceived(Session.java:301)
at net.sf.jml.net.Session.access$1200(Session.java:30)
at net.sf.jml.net.Session$MsgDispatcher.run(Session.java:283)
at java.lang.Thread.run(Thread.java:722)
2011-11-15 17:59:51,359 [net.sf.jml.net.SocketSession.msgDispatcher] INFO [net.sf.jml.protocol.soap.ContactList] - Error xml:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><ServiceHeader xmlns="http://www.msn.com/webservices/AddressBook"><Version>16.02.2225.0001</Version><CacheKey>14r2;bbpT2KMyAQeqUGL2pLhFFIW3+ye7cNYX5M2PX0c8z0ZmUJNekjieQ2lyubqcM9oT0xiBZ72ftMeO8Z0G8VS7Kkb8ZW6Qy+LneCjoa/hqyitiGwTWU7iy8CIDp5xmT7BxZ5cmjiolg7iIAfYsM8XDHA3d4BRljM3PfZL7341yc2w=</CacheKey><CacheKeyChanged>true</CacheKeyChanged><PreferredHostName>proxy-sn.contacts.msn.com</PreferredHostName><SessionId>ABCH.a6847870-918c-4bc9-8327-589b0f33c57a</SessionId></ServiceHeader></soap:Header><soap:Body><FindMembershipResponse xmlns="http://www.msn.com/webservices/AddressBook" /></soap:Body></soap:Envelope>
引用
MyJmsnClient start ...
2011-11-15 17:59:44,703 [net.sf.jml.net.SocketSession.msgDispatcher] INFO [com.talent.platform.demo.openfire.msn.my.MyJmsnSimpleAdapter] - MSN login success with ID=tanyaowu45@hotmail.com
2011-11-15 17:59:51,343 [net.sf.jml.net.SocketSession.msgDispatcher] ERROR [net.sf.jml.protocol.soap.ContactList] - something wrong!
java.lang.Exception
at net.sf.jml.protocol.soap.ContactList.sendRequest(ContactList.java:276)
at net.sf.jml.protocol.soap.ContactList.sendRequest(ContactList.java:271)
at net.sf.jml.protocol.soap.ContactList.sendRequest(ContactList.java:160)
at net.sf.jml.protocol.soap.ContactList.dispatch(ContactList.java:395)
at net.sf.jml.protocol.incoming.IncomingUSR.messageReceived(IncomingUSR.java:150)
at net.sf.jml.protocol.MsnSession$1.messageReceived(MsnSession.java:107)
at net.sf.jml.net.Session.fireMessageReceived(Session.java:301)
at net.sf.jml.net.Session.access$1200(Session.java:30)
at net.sf.jml.net.Session$MsgDispatcher.run(Session.java:283)
at java.lang.Thread.run(Thread.java:722)
2011-11-15 17:59:51,359 [net.sf.jml.net.SocketSession.msgDispatcher] INFO [net.sf.jml.protocol.soap.ContactList] - Error xml:<?xml version="1.0" encoding="utf-8"?><soap:Envelope xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsd="http://www.w3.org/2001/XMLSchema"><soap:Header><ServiceHeader xmlns="http://www.msn.com/webservices/AddressBook"><Version>16.02.2225.0001</Version><CacheKey>14r2;bbpT2KMyAQeqUGL2pLhFFIW3+ye7cNYX5M2PX0c8z0ZmUJNekjieQ2lyubqcM9oT0xiBZ72ftMeO8Z0G8VS7Kkb8ZW6Qy+LneCjoa/hqyitiGwTWU7iy8CIDp5xmT7BxZ5cmjiolg7iIAfYsM8XDHA3d4BRljM3PfZL7341yc2w=</CacheKey><CacheKeyChanged>true</CacheKeyChanged><PreferredHostName>proxy-sn.contacts.msn.com</PreferredHostName><SessionId>ABCH.a6847870-918c-4bc9-8327-589b0f33c57a</SessionId></ServiceHeader></soap:Header><soap:Body><FindMembershipResponse xmlns="http://www.msn.com/webservices/AddressBook" /></soap:Body></soap:Envelope>
发表评论
-
tomcat注册成windows服务
2012-05-10 15:24 1075详见:http://www.micmiu.com/ ... -
tomcat https配置示例
2012-05-10 15:19 1025详见 :http://www.micmiu.com/en ... -
条形码/二维码之开源利器ZXing图文介绍
2011-08-08 13:21 39574blog迁移至 :http://www ... -
Java实现二维码QRCode的编码和解码
2011-08-01 08:47 40014blog迁移至 :http://www.m ... -
Java简单实现Ping功能
2011-07-22 06:05 5208blog迁移至 :http://www.micmiu. ... -
SMSLib实现Java短信收发的功能
2011-05-16 12:52 12031blog迁移至:http://www.micmiu.c ... -
Log4j输出日志到syslog
2011-03-15 13:22 6697blog迁移至:http://www.micmiu.c ... -
Log4j使用详解
2010-12-30 18:44 2826blog迁移至:http://www.micmiu.c ... -
Java实现简单whois查询
2010-06-07 21:57 3087blog迁移至:http://www.micmiu.c ...
相关推荐
本文将探讨如何使用Java语言实现MSN Messenger的功能,主要涉及的知识点包括Java编程、即时通讯协议(IM)、JML库以及相关的第三方库。 **JML库介绍** JML(Java Messenger Library)是专为Java开发者设计的一个库...
在本文中,我们将深入探讨如何使用Java来实现MSN(Microsoft Messenger Service)的收发消息功能。MSN曾经是一款流行的即时通讯软件,尽管它现在已经不再维护,但它的协议仍然是学习网络通信和即时消息处理的一个...
MSN Messenger(现已更名为Windows Live Messenger)曾经是流行的即时通讯工具,而Java版MSN项目则是开发者尝试用Java来复现这一功能的成果。通过研究这些源码,我们可以深入理解以下知识点: 1. **Java网络编程**...
Java版的即时通信软件,正如标题所提及的“Java版msn即时通信软件”,是一种基于Java编程语言开发的在线通讯工具,旨在实现类似MSN Messenger的功能。MSN Messenger是微软公司曾经推出的一款广泛使用的即时通讯应用...
在MSN Messenger中,TypeLib定义了各种接口和类,这些接口和类是实现服务功能和交互的关键。例如,它可能包含登录、发送消息、添加联系人等操作的接口定义。通过引用TypeLib,开发者可以轻松地在代码中调用这些接口...
标题中的"MSN.rar_java msn_msn_msn j2_msn mobile"暗示了这是一个关于MSN(微软网络Messenger)的项目,特别关注其在Java平台上,尤其是J2ME(Java 2 Micro Edition)环境下的实现,适合移动设备如手机。...
由于MSN Messenger在2013年已停服,这款Java版的程序可能是一个开源或者非官方的替代品,允许用户通过网络进行文字聊天、语音通话、文件传输等功能。 Java作为一种跨平台的编程语言,使得这个Java版的MSN程序具有...
JavaMSN项目是一个基于Java语言实现的MSN Messenger接口,它允许开发者通过编程方式与MSN网络进行交互,实现诸如发送和接收消息、管理联系人列表、处理在线状态更新等功能。这个项目通常对那些希望在自己的应用程序...
MSN Messenger模仿界面是一个关于创建类似MSN Messenger的用户界面的设计与实现项目。MSN Messenger,作为一款曾经流行的即时通讯软件,以其简洁、直观的界面设计深受用户喜爱。本项目旨在通过编程技术,模仿其核心...
JavaMSN是一款基于Java编程语言开发的网络聊天工具,模仿了微软的MSN Messenger服务。这个项目由一位韩国开发者创建,旨在提供跨平台的即时通讯解决方案,因为Java语言的“一次编写,到处运行”特性使得JavaMSN可以...
【Java版MSN(TjMSN)】是一款基于Java编程语言实现的即时通讯软件,它模仿了经典的MSN Messenger服务,为用户提供跨平台的聊天、文件传输等基本功能。在2009年10月20日时,这款软件已被证实可以正常运行并使用。 ...
2. **网络通信协议**:MSN Messenger使用了专有的实时通信协议,包括MSNP(MSN Messenger Protocol)和WLM(Windows Live Messenger Protocol)。通过分析源码,我们可以学习如何实现这些协议,包括消息传递、状态...
Java模仿的MSN聊天软件是一个基于Java编程语言实现的即时通讯应用,它借鉴了早期流行的MSN Messenger的功能和设计,旨在提供类似的文字、语音甚至视频聊天体验。在这个项目中,开发者使用Java的技术栈来创建一个...
JavaMSN实例是一个基于Java编程语言实现的项目,它展示了如何使用Java来登录MSN即时通讯平台并发送消息。在本文中,我们将深入探讨这个过程中的关键知识点,包括Java网络编程、MSN协议理解、以及如何构建这样的应用...