Here is a Java bean that allows to chat on a Forms application

Chat on Forms

It uses a modified version of the socketserver sample.
The list of chatters is held by a database table (CHAT) and a database package (PKG_CHAT) that get and dispatch the messages from/to the connected users.

REM Create the CHAT table
  PORT       NUMBER(5,0),
  NAME       VARCHAR2(100 BYTE),

The sample dialog provided with the bean allows to test the chat system.
When a chatter just connects, you can see his/her name in the chatters list.
Check the check-box if you want he/her receives your messages.
In the To send text box, use the Tab key to send the message.

The Java code

     ChatClient.java     ChatServer.java

The implementation class of the Bean Item


The methods you can call

Init the socket server

Set_Custom_Property('BLOCK.ITEM', 1, 'INIT_SERVER', 'port_number');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'INIT_SERVER', '4450' ) ;

Stop the socket server

Set_Custom_Property('BLOCK.ITEM', 1, 'STOP_SERVER', '');

e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'STOP_SERVER', '' ) ;

The event received from the Bean


this event tells Forms that a message is sent by the Java Bean.
You can get it in a WHEN-CUSTOM-ITEM-EVENT event:

    eventName varchar2(30) := :system.custom_item_event;
    eventValues ParamList;
    eventValueType number;
    LC$Msg    varchar2(32000);
    LC$Value  varchar2(256);
   IF (eventName='SENDMSG') THEN
      eventValues := get_parameter_list(:system.custom_item_event_parameters);
      get_parameter_attr(eventValues,'MESSAGEVALUE',eventValueType, LC$Msg);
      -- Socket Server OK --
      If LC$Msg = '[SocketServerOK]' Then
        Set_Item_Property( 'BL.START', LABEL, 'Disconnect' ) ;
        :BL.STATUS := 'Connected on port ' || :BL.PORT  || CHR(10) || :BL.STATUS;
        Pkg_Chat.Open_Connexion( :BL.IP, :BL.PORT, :BL.NAME);
      -- new connexion --
      ElsIf Instr( LC$Msg, '[conn]' ) > 0 Then
        bell ;
        Query_Users ;
        :BL.STATUS := 'Connection of ' || Replace(LC$Msg,'[conn]','' )  || CHR(10) || :BL.STATUS;
      -- Deconnexion --
      ElsIf Instr( LC$Msg, '[deconn]' ) > 0 Then
        bell ;
        :BL.STATUS := 'Disconnection of ' || Replace(LC$Msg,'[deconn]','' )  || CHR(10) || :BL.STATUS;
        Query_Users ;
      -- Standard message --
         Add_Text( Replace(LC$Msg,'^',CHR(10)) ) ;
      End if ;
      Synchronize ;           
   END IF;

The sample dialog

     . Download the socketserver.zip file
     . Unzip the file
     . run the chat.sql script on your database (The user must have access to the UTL_TCP package)
     . copy the chat.jar file in the <ORACLE_HOME>/forms/java directory
     . Edit your /forms/server/formsweb.cfg file
     . Open the CHAT.fmb module (Oracle Forms 9.0.2)
     . Compile all and run the module

     the jar file must be signed.
     the jar file provided in this article is already signed.