Sample JOscarLib Program

  • Wong Ka Ho Matthew


    i'm playing with JOscarLib, and i've no idea on how to get it work. :)

    i'm short sure if i'm using those classes in the the right way, anyone, pls comment:

    import JOscarLib.*;
    import JOscarLib.Core.*;
    import JOscarLib.Setting.Enum.StatusModeEnum;

    class icq {
        public static void main (String[] args)
            String host     = "";
            int    port     = 5190;
            String userId   = "123456789";
            String password = "123321";

            OscarInterface  oscarInterface  = new OscarInterface();
            OscarConnection oscarConnection = new OscarConnection (host, port, userId, password);

            oscarInterface.changeStatus(oscarConnection, new StatusModeEnum(StatusModeEnum.ONLINE));
            oscarInterface.sendMessage(oscarConnection, "987654321", "test");

    • Wong Ka Ho Matthew

      here's the output:

      E:\tmp\test\icq>javac -classpath .;JOscarLib0.2.1beta1-Bin.jar
      E:\tmp\test\icq>java  -cp        .;JOscarLib0.2.1beta1-Bin.jar icq

      Exception in thread "main" java.lang.NullPointerException
              at JOscarLib.Core.OscarClient.getInetaddress(
              at JOscarLib.OscarInterface.changeStatus(
              at icq.main(

    • Michellonet Fabrice


      First, i'm sorry for answering so late to your message...

      Anyway you've guessed quite perfectly how to use JOscarLib, but :

      1 - Instanciate OscarConnection, create a thread that will manage the communication with ICQ, so till the connection isn't establish you shouldn't do anything (msg etc..)

      2 - To know when you're connected implements Observer interface.

      3 - There is a bug in the naming of the jar file, you must rename JOscarLib0.2.1beta1-Bin.jar to JOscarLib.jar. This will be fixed today in the new release along with new documentation.

      Here is a sample code that works :

      import java.util.*;

      import JOscarLib.*;
      import JOscarLib.Core.*;
      import JOscarLib.Setting.Enum.*;

      class Icq implements Observer {

        private String host = "";
        private int port = 5190;
        private String userId = "123456789";
        private String password = "123321";

        private OscarInterface oscarInterface;
        private OscarConnection oscarConnection;

        public Icq() {
          oscarInterface = new OscarInterface();
          oscarConnection = new OscarConnection(host, port, userId, password);
          /* To be notified */

        /* This is executed when you're logged in */
        public void update(Observable obs, Object obj) {
           * If you only have a little amount of things to do, you can code them here.
           * But if you've planned to code something more consistent, you should only
           * set a flag that indicate that you're online. Then, anywhere else in your
           * code you test this flags and if it is true you can send a message for example.
                                      new StatusModeEnum(StatusModeEnum.ONLINE));
          oscarInterface.sendMessage(oscarConnection, "987654321", "test");

        public static void main(String[] args) {
          Icq icq = new Icq();

    • Wong Ka Ho Matthew

      thanks very much for the sample program. i can now get my little icq client and send a message to my real icq. :)

      thanks again!

    • Robson Dantas silva


      Im a brazilian coder!
      Nice to meet you!!!

      I did all the things that you describe...
      but when I run the software, it doesnt do anything..

      im using red hat 7.0 with iptables.. and i dont know if it is the real problem (it likes a infinite loop)

      can you help me?

      • Michellonet Fabrice

        Nice to meet you too ;-)

        Sure, i'll try to help you...

        Ok! First, did you download the last release ? If so, is JOscarLib.jar in your classpath when you execute your program ?
        [i.e : java -cp JOscarLib.jar MY_CLASS]

        Did you try to compile and execute the sample programs that comes with the Library ?

        If it even don't work with "" please set the debug mode by adding this line in the program :


        and then please post the output of the program on this forum.

        Anyway, sample programs should really works as i've tried them on many computers, running differents OS; thought i've never tried it on ReadHat 7.

    • Robson Dantas silva

      thats the message that I got...

      Received 1 - 3 .

      but the "update" method is not called..
      if I turn my icq on and try to connect with the software a got the message. "Your icq is used on another computer"...

      but dont work....

      Robson - Brazil

      • Michellonet Fabrice

        Ok, that's what i thought. A connection is established with ICQ servers but JOscarLib.jar isn't in your classpath when you're executing the class.

        JOscarLib dynamically loads class from the jar file when they are needed. If JOscarLib.jar isn't in your classpath the program will freeze (infinite loop).

        On a linux box type :
        # cd "in the working directory"
        # javac -classpath JOscarLib.jar
        # java -cp JOscarLib.jar: SampleMinimalistic

        If you're using an IDE [like JBuilder or Eclipse] to program, double check your path. If it really don't work with your IDE, try to do it manually in a console.

        Good luck and let me know if it worked.

        • Yven Johannes Leist

          [posting to this thread since we have a similar problem]

          We considered integrating JOscar as a plugin into XNap (filesharing client written in Java) but failed to connect to a server via the sample code provided some posts above. We tried both the default as well as with icq UIN's and aim screenames but only the "Received 1-3" appeared. Comparing the tcp logs it generated with one from Gaim we noticed astonishing differences: Whereas Gaim produced SNAC data packages containing the signon information JOscar immediately sent a close command after the "New Connection" (Gaim did that only after the signon messages) and then after the next connection message the server returned "Server is now ready for normal function"  to which JOscar responded "Unknown Channel" (which seems due to strange Channel ID's being sent out earlier by JOscar).

          Any idea as to what the problem could be?
          If it's of any help we could provide the logfiles generated by tcdump.

          Yven Leist

          • Michellonet Fabrice


            I'm honored XNap's developpers are interested in JOscarLib.

            If the sample program seems to freeze after the message : "Received 1-3",  that means that JOscarLib.jar isn't in your classpath.
            To execute the sample, on linux type: "java -cp JOscarLib.jar: MY_CLASS"
            on Windows type: "java -cp JOscarLib.jar; MY_CLASS"
            [Note the classpath separator. It's ":" on Linux and ";" on Windows]

            If you have downloaded JOscarLib0.2.1beta1 you must rename JOscarLib0.2.1beta1-Bin.jar to JOscarLib.jar

            Yesterday, i've released the version 0.2.2 beta1 which came with several samples. Try to execute SampleMinimalistic. This sample works if JOscarLib is in your classpath when you ececute it.
            You should really download the last release as i've corrected some bugs.

            For the differences, you've noted on the packets that are sent, i must admit that i've never had a look on how GAIM login on Oscar servers.
            I've based my Library on specs i've found on :  (which seems to be the more reliable source) and on dumps i've made of the official client.
            By the way, i know GAIM send some non standard packets, containing GAIM specifics capabilities etc...
            Anyway, i'd like to have a look to your dumps, may you mail them ?

            I hope this has helped.
            If you still experience problems, don't hesitate to post here.


            • Felix Berger

              Felix Berger - 2003-04-26

              Hi Fabrice,

              thanks for answering.

              In the meantime we have developed a joscar plugin based on your library.

              Most features seem to rudimentarily work. Unfortunately there is one problem:

              Your library doesn't seem to run properly if the jar file JOscarLib.jar isn't located in the current working directory.

              Here is how XNap usually is started:

              java -classpath /usr/java/j2sdk1.4.1_02/jre/lib/rt.jar:.:lib/libreadline-java-0.7.jar:lib/jd3lib.jar:lib/gnu.getopt-1.0.9.jar:lib/kunststoff-2.0.1.jar:lib/log4j-1.2beta3.jar:lib/xnap-ziga.jar:lib/jtella-0.7.jar:lib/pircbot-1.0.3.jar:lib/JOscarLib.jar:lib/jh.jar:.:/usr/java/j2sdk1.4.1_02/jre/lib/rt.jar::doc/xnap-manual xnap.XNap -d

              This doesn't work for the icq library.

              We hope you can have look at that matter. Our first guess would be that maybe something goes wrong in your JarClassLoader code.

              Another thing:

              We managed to log in using icq uins, but didn't have any luck using AIM screennames, isn't oscar the new protocol used by both AIM and ICQ?


              • Michellonet Fabrice

                hi Felix,

                >Most features seem to rudimentarily work
                Why do you say rudimentarily ? Which feature(s) do you need ? I encourage users to tell me what they need.

                You're right by now JOscarLib only works if the jar file is located in the working directory. In fact adding JOscarLib.jar to the classpath isn't enought to make it work. The problem is that the jar file has to be accessed during execution to dynamically load some classes.
                I'm going to fix this really soon.
                Anyway, until the next release, you could hardcode the path to JOscarLib in he constructor of OscarPacketAnalyser class.
                EX : jarClassLoader = new JarClassLoader("path/to/JOscar/JOscarLib.jar", "JOscarLib.Packet.Received");

                >We managed to log in using icq uins, but didn't have any luck using AIM screennames, isn't oscar the new protocol used by both AIM and ICQ?

                You're right, Oscar is the protocol used by ICQ & AIM client, but each one also implements ~10% of proprietary protocol [for example ICQ send a specific packet at login time to tell the server, it's an ICQ client.]
                I need to work on AIM login sequence to make it work again. That's one of my highest priority.


            • Felix Berger

              Felix Berger - 2003-04-26

              Hi Fabrice,

              this is what I just found out:

              I added some debug messages to your library code and the problem seems to be that your JarClassLoader can't load the Packet classes needed by the OscarPacketAnalyser.

              But even after I moved the modified library to the working directory, several packets could not be loaded.

              Here is the log:
              Received 1 - 3
              --> JOscarLib.Packet.Received.ServerReady__1_3 loaded
              Received 1 - 24
              --> JOscarLib.Packet.Received.Icq.ServerIcqAcknowledge__1_24 loaded
              Received 1 - 19
              Could not load class 1 19
              Received 1 - 7
              --> JOscarLib.Packet.Received.RateResponse__1_7 loaded
              Received 1 - 15
              Could not load class 1 15
              Received 2 - 3
              Could not load class 2 3
              Received 3 - 3
              Could not load class 3 3
              Received 4 - 5
              Could not load class 4 5
              Received 9 - 3
              --> JOscarLib.Packet.Received.BosRightResponse__9_3 loaded
              Received 1 - 15
              Could not load class 1 15
              Received 11 - 2
              Could not load class 11 2
              Received 1 - 15
              Could not load class 1 15
              Received 3 - 11
              --> JOscarLib.Packet.Received.IncomingUser__3_11 loaded
              Received 21 - 3
              --> JOscarLib.Packet.Received.Icq.ServerMeta__21_3 loaded
              Received 3 - 11
              --> JOscarLib.Packet.Received.IncomingUser__3_11 loaded
              Received 4 - 1
              Could not load class 4 1
              Received 4 - 1
              Could not load class 4 1
              Received 4 - 1
              Could not load class 4 1
              Received 4 - 7
              Server error : Problem due to : null

              I got the last error, when I tried to im the client form a gaim client.

              Hope to hear from you soon, the plugin looks pretty promising.


              The modified code:


              private void cacheClasses(String jarFileName, String packageName) {
                  try {
                    JarFile jarFile = new JarFile(jarFileName);
                    Enumeration entries = jarFile.entries();
                    while (entries.hasMoreElements()) {
                      JarEntry entry = (JarEntry) entries.nextElement();
                      if (match(normalize(entry.getName()), packageName)) {
                  catch (IOException IOE) {
                      /* Simply nothing will added to the Vector */
                      System.out.println("Could not cache class " + jarFileName + " "
                                         + packageName);


              if ( (loadedClass = jarClassLoader.loadClass(familyId, subTypeId)) != null) {
                    rcvp2 = (ReceivedPacket) loadedClass.newInstance();
                      System.out.println("--> " + loadedClass.getName() + " loaded");
                  else {
                      if (debug) {
                          System.out.println("Could not load class " + familyId + " "
                                             + subTypeId);

              • Michellonet Fabrice

                hi Felix,

                >But even after I moved the modified library to the working directory, several packets could not be loaded.

                As you might know, Oscar protocol isn't open source. That means that we must dump incoming packets and then try to figure out what they mean.
                At the time, there are several packets we still do not understand, other do not contains relevant informations. For example Snac 1-19 is the message of the day, Snac 1-21 contains ads etc...
                So when the lib receive one of those packets, it just do NOTHING, that why no classes are loaded.

                >I got the last error, when I tried to im the client form a gaim client.

                Was the gaim client logged as an ICQ or AIM user ?
                Anyway, gaim developpers have added some "special" or "unofficial" packets that do not respect the Oscar protocol. If you were logged as an AIM user, that's why the lib has bugged [as i told you in the last post i still have to fully support AIM], if you were logged as an ICQ user.... well i should work on this bug immediatly. ;-)



    • Robson Dantas silva


      that works...

      i forgott the ";" after JOscarLib.jar


      im developing a icq clone using java...
      ill talk to you when a finish a the first binary...


      • Michellonet Fabrice

        Great !

        ok, let me know when you'll have a first version.

    • Didier Ernotte

      Didier Ernotte - 2003-04-25

      I am trying to use this library with our ICQ Corporate server version 1.1.2. Is there any difference in the protocole between the public ICQ server and the Corporate server ?

      • Michellonet Fabrice


        i'm sorry to answer so late, but i had to find some info about ICQ Corporate servers. I've never had the chance to work with one of those server, so i not certain that the protocol differs.
        But i've read on some forums that those servers still use the version 5 of the protocol. Public ICQ servers support version 7 & 8 of the protocol.
        So that's probably why my lib do not work with your corporate server.

    • Didier Ernotte

      Didier Ernotte - 2003-04-29

      Ok, thanks.
      Do you know a java lib implementing the version 5 of the protocol for ICQ ?

      • Michellonet Fabrice

        I'm sorry, I don't think you'll find any V5 library written in Java.
        Maybe you'll have more luck with some old lib in C.

        Why don't you use a V7/8 server ? There is an open source server called iserverd :
        I've heard that it works really good.

        Then you could use JOscarLib with iserverd....

    • Adam Walsh

      Adam Walsh - 2003-05-06

      Hi everyone,

      After managing to connect successfully once, I seem to be getting the following error whenever I try to connect:

      Server error : Problem due to : Error Code (24) : Rate Exceeded

      what exactly does "rate exceeded" mean? Thanks in advance!

      • Michellonet Fabrice

        That means that you're reconnecting to fast to the server, or that you've made too many connection in a little time.

        You can have the same error using the official client.


Get latest updates about Open Source Projects, Conferences and News.

Sign up for the SourceForge newsletter:

No, thanks