2011-04-01 18 views

答えて

3

無料のJava APIがあります。hereです。以下の抜粋は、メッセージの送信方法の簡単な例です。

final STSession session = new STSession("SameTimeSender"); 
session.loadAllComponents(); 
session.start(); 

CommunityService comm = (CommunityService) session.getCompApi(CommunityService.COMP_NAME); 
comm.addLoginListener(new LoginListener() { 

    public void loggedOut(LoginEvent arg0) { 
    } 

    public void loggedIn(LoginEvent arg0) { 
     LookupService lookup = (LookupService) session.getCompApi(LookupService.COMP_NAME); 
     Resolver resolver = lookup.createResolver(true, false, true, false); 
     resolver.addResolveListener(new ResolveListener() { 

      public void resolved(ResolveEvent re) { 
       STUser user = (STUser) re.getResolved(); 

       InstantMessagingService imservice = (InstantMessagingService) session.getCompApi(InstantMessagingService.COMP_NAME); 

       final Im im = imservice.createIm(user, EncLevel.ENC_LEVEL_NONE, ImTypes.IM_TYPE_CHAT); 
       im.addImListener(new ImListener() { 

        public void textReceived(ImEvent arg0) { 
        } 

        public void openImFailed(ImEvent arg0) { 
        } 

        public void imOpened(ImEvent arg0) { 
         im.sendText(false, "hello world!"); 
        } 

        public void imClosed(ImEvent arg0) { 
        } 

        public void dataReceived(ImEvent arg0) { 
        } 
       }); 
       im.open(); 
      } 

      public void resolveFailed(ResolveEvent arg0) { 
      } 

      public void resolveConflict(ResolveEvent arg0) { 
      } 
     }); 

     resolver.resolve(recipientId); 
    } 
}); 

comm.loginByPassword(hostname, userId, password); 
関連する問題