]> git.evergreen-ils.org Git - OpenSRF.git/blob - src/java/org/opensrf/test/TestXMPP.java
8a34a2eb4c4151e7a996101dd0b4d5c032343a82
[OpenSRF.git] / src / java / org / opensrf / test / TestXMPP.java
1 package org.opensrf.test;
2
3 import org.opensrf.net.xmpp.XMPPReader;
4 import org.opensrf.net.xmpp.XMPPMessage;
5 import org.opensrf.net.xmpp.XMPPSession;
6
7 public class TestXMPP {
8
9     public static void main(String args[]) throws Exception {
10
11         String host;
12         int port;
13         String username;
14         String password;
15         String resource;
16         String recipient;
17
18         try {
19             host = args[0];
20             port = Integer.parseInt(args[1]);
21             username = args[2];
22             password = args[3];
23             resource = args[4];
24
25         } catch(ArrayIndexOutOfBoundsException e) {
26             System.err.println("usage: org.opensrf.test.TestXMPP <host> <port> <username> <password> <resource>");
27             return;
28         }
29
30         XMPPSession session = new XMPPSession(host, port);
31         session.connect(username, password, resource);
32
33         XMPPMessage msg;
34
35         if( args.length == 6 ) {
36             /** they specified a recipient */
37             recipient = args[5];
38             msg = new XMPPMessage();
39             msg.setTo(recipient);
40             msg.setThread("test-thread");
41             msg.setBody("Hello, from java-xmpp");
42             System.out.println("Sending message to " + recipient);
43             session.send(msg);
44         }
45
46         while(true) {
47             System.out.println("waiting for message...");
48             msg = session.recv(-1);
49             System.out.println("got message: " + msg.toXML());
50         }
51     }
52 }
53
54
55
56
57