Java Help
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesJava Help

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old December 8th, 2002, 02:59 AM
Sonic98 Sonic98 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Memphis, TN
Posts: 195 Sonic98 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 44 sec
Reputation Power: 6
Send a message via AIM to Sonic98 Send a message via Yahoo to Sonic98
Java class help

I have to admit I have little experience with java. I mainly program with some of the older languages. I was reading information about setting up a messaging client, and I have no idea what he is talking about in the last step.


Send your first Jabber message
To send a Jabber instant message programmatically, you must initialize the Muse Jabber API. Do that by creating an instance of the JabberContext class, then use the context as a parameter to the createSession() method on the Jabber session factory class:

1 // Initialize the Jabber context
2 JabberContext jabberContext = new JabberContext("user", "pass", "localhost");
3
4 // Create an instance of the Jabber session factory
5 Jabber jabber = new Jabber();
6 // Create the new session
7 JabberSession jabberSession = jabber.createSession(jabberContext);


The above example shows the creation of a new context at line 2. The JabberContext stores specific user-related information (username, password, server address) and also contains a unique session identifier when the session is later established using the context. For illustration purposes, I have hardcoded the username, password, and server.

At line 5, a Jabber session factory is created, which we use at line 7 to create a new JabberSession, Muse's main interface into the services offered by the Jabber server. The server's main services are:


Connection services: For connecting to and disconnecting from the Jabber server
User service: For user authentication and registration
Presence service: For receiving presence information from other users/services and broadcasting your own presence
Roster service: Jabber-speak for a buddy list or address book
Chat service: Sends messages of various types—group chat, private messages, headlines, and so on
Server service: Obtains information relating to the services offered by this Jabber server
Client service: Obtains information about other users, such as the last time the user signed in
Now that we have an initialized Jabber session, we can use it to connect to the Jabber server using the connect() method on the JabberSession object we just created:

8 // Connect to the server
9 jabberSession.connect("localhost", 5222);


To connect to a Jabber server, we specify the address and port number of the machine on which the server is located. The standard, default Jabber port number is 5222 and should rarely change.

Now that the JabberSession has connected to the server, we can log in with the login() method on the user service:

10 // Log in to the Jabber server
11 jabberSession.getUserService().login();


At line 11, we use the JabberSession to obtain a reference to the UserService, then call the login() method on the user service. Notice that the method itself did not specify any user information. login() obtains this information from the JabberContext associated with the JabberSession when the JabberSession was created at line 7 above.

Now that we have successfully logged in to the Jabber server, we can start sending and receiving messages. The following code fragment shows how to construct a simple headline-style message:

12 // Construct test message
13 JabberChatMessage msg = new
14 JabberChatMessage(JabberChatMessage.TYPE_HEADLINE);
15 msg.setSubject("Hello world");
16 msg.setBody("Hello world");
17 msg.setTo("user2@localhost");


At line 13, we create a JabberChatMessage instance. The single parameter specifies the type of message we require: TYPE_HEADLINE. The name of the JabberChatMessage class is a little misleading because, in fact, it might be used to contain any of the four types of messages—normal, chat, headline, and error—defined in the Jabber protocol. At line 15, setSubject() and setBody() specify the subject and body texts, respectively. Finally, setTo() sets the JID of the message's receiver at line 17.

Under the covers, the JabberChatMessage converts all of this information into an internal DOM (Document Object Model) tree so the XML can generate easily when we are ready to send the message to the Jabber server.

The final step: Send the message using the sendMessage() method:

18 // Send the message
19 jabberSession.sendMessage(msg);

Last edited by Sonic98 : December 8th, 2002 at 03:01 AM.

Reply With Quote
  #2  
Old December 9th, 2002, 07:22 AM
Shocka's Avatar
Shocka Shocka is offline
dont click here
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Jun 2002
Posts: 409 Shocka User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 7 h 35 m
Reputation Power: 7
looks pretty straight foward to me (ive also be programming in Java for about 4 years now).. can u possibly highlight the lines ur confused about.

Reply With Quote
  #3  
Old December 9th, 2002, 09:11 AM
Sonic98 Sonic98 is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Dec 2002
Location: Memphis, TN
Posts: 195 Sonic98 User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 16 m 44 sec
Reputation Power: 6
Send a message via AIM to Sonic98 Send a message via Yahoo to Sonic98
Well nevermind now. I have found come classes already compiled. I guess I should have taken java and pay more attention in my C++ classes. The only problem with the applets I found is they are in jar. I might be wrong, but I thought people could only open those applets if they download suns java machine as opposed to the one built into IE. Wouldn't I have it recompile for them to work with IE?

Reply With Quote
Reply

Viewing: Dev Shed ForumsProgramming LanguagesJava Help > Java class help


Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump


Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 





© 2003-2008 by Developer Shed. All rights reserved. DS Cluster 1 hosted by Hostway