xmpp 기반android단 실시간 통신 실현 ---asmack 기본 방법 (1)

asmack의 기본 사용
모두 프로그래머입니다. 코드를 바로 올립니다.
//      connection.isConnected();
//       connection.disconnect();

  
XmppConnection.getConnection().login(accounts, password);
			Presence presence = new Presence(Presence.Type.available);       //       
			XmppConnection.getConnection().sendPacket(presence);
//  
Registration reg = new Registration();
		reg.setType(IQ.Type.SET);
		reg.setTo(XmppConnection.getConnection().getServiceName());
		reg.setUsername(accounts);
		reg.setPassword(password);
		reg.addAttribute("name", nicheng);
		reg.addAttribute("email", email);
		
		PacketFilter filter = new AndFilter(new PacketIDFilter(
		                                reg.getPacketID()), new PacketTypeFilter(
		                                IQ.class));
		PacketCollector collector = XmppConnection.getConnection().
		createPacketCollector(filter);
		XmppConnection.getConnection().sendPacket(reg);
		IQ result = (IQ) collector.nextResult(SmackConfiguration
		                                .getPacketReplyTimeout());
		                        // Stop queuing results
		collector.cancel();//     results(       )
  :
AccountManager amgr = connection.getAccountManager();
			amgr.createAccount(account, "111");

//    ,     、   
Presence presence = new Presence(Presence.Type.available);  
        presence.setStatus(status);  
        connection.sendPacket(presence);


//    
Roster roster = conn.getRoster();
Collection<RosterGroup> groups = roster.getGroups();

//        
Roster roster = XmppConnection.getConnection().getRoster();
roster.getEntries();

//    
   :
ChatManager cm = connection.getChatManager();		
				//     pc      (        ,   )
				Chat newchat = cm.createChat("111@d3studio", null);
					newchat.sendMessage("hi");

//      
MessageInterceptor mMessageInterceptor = new MessageInterceptor();
XmppConnection.getConnection().addPacketInterceptor(
				mMessageInterceptor,
				new PacketTypeFilter(Message.class));      //           ,          

//      
 		MessageListener mMessageListener = new MessageListener();
		XmppConnection.getConnection().addPacketListener(mMessageListener,
				new PacketTypeFilter(Message.class));
//      ,        ,            
FileTransferManager fileTransferManager = new FileTransferManager(XmppConnection.getConnection());
		fileTransferManager.addFileTransferListener(new ImgListener());

//    
FileTransferManager manager = new FileTransferManager(XmppConnection.getConnection());  
        OutgoingFileTransfer imgSend = manager.createOutgoingFileTransfer(“jid@server/Smack”);  
        imgSend.sendFile(file,file.getName());

//    ,    
FileTransferListener
@Override
		public void fileTransferRequest(final FileTransferRequest request) {
			imgCome = request.accept();
File file = new File(XmppConnection.SAVE_PATH + "/"+ request.getFileName());  //      
imgCome.recieveFile(file);
}

좋은 웹페이지 즐겨찾기