Overblog
Suivre ce blog
Editer l'article Administration Créer mon blog
6 novembre 2006 1 06 /11 /novembre /2006 10:42

Purpose

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
CREATE TABLE CHAT
(
  IP_ADDRESS VARCHAR2(15 BYTE),
  PORT       NUMBER(5,0),
  NAME       VARCHAR2(100 BYTE),
  FIRST_CONN DATE
)
/


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 chatter list.
Check the check-box if you want he/she 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

    oracle.forms.fd.ChatClient


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

  • SENDMSG

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

DECLARE
   
    eventName varchar2(30) := :system.custom_item_event;
    eventValues ParamList;
    eventValueType number;
    LC$Msg    varchar2(32000);
    LC$Value  varchar2(256);
   
BEGIN
   
   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 --
      Else
         Add_Text( Replace(LC$Msg,'^',CHR(10)) ) ;
      End if ;
      Synchronize ;           
   END IF;
   
END;


The sample dialog

     . Download the chat.zip file
     . Unzip the file
     . run the chat.sql script on your database (the Oracle 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.

Partager cet article

Published by Oracle Forms community - dans Bean - general
commenter cet article

commentaires

Sahyouni 20/05/2015 11:10

I have tried to run the form after I have performed all steps but I keep getting the following error message "CLIENT MACHINE IP NOT AVAILABLE"
Please help...
Thanx

heythem 11/06/2007 12:36

this is the messages of the  JAVA CONSOL
Downloading to JAR cache
RegisterWebUtil - Loading WebUtil Version 1.0.6
Loading  from JAR cache
Loading  from JAR cache
Loading  from JAR cache
Loading  from JAR cache
Loading  from JAR cache
proxyHost=null
proxyPort=0
connectMode=HTTP, native.
Forms هو : 9.0.4.3
ServerSocket is running    // for the first acces is oki but after nothing can connect
Error : unable to create socket
Error : unable to create socket

Oracle Forms community 11/06/2007 14:13

Add  : Set_Custom_Property( 'BL.BEAN', 1, 'STOP_SERVER', '' ) ; in a key-exit trigger to enforce the Socket Server to stop before exiting the Form.Francois

Heythem 11/06/2007 11:38

Sorry francois for speaking french  i don't khnow that i must speak english.
So thanks for your reply,but the probleme is not in DECONNECTION but in the CONNECTION, in the first run of  form she run perfectly and the status "Connected on port 4450 " but if i exit  the form and i return to connect in the same session  the status below stoped on OPEN PORT 4450 ON.. and nothing after  and I select * from chat  no rows so i'm not connected to the local machine on port 4450.
For run the chat again and have the connection i must closed  application and accede for a new session, so i thing that the CONNECTION PROCEDURE modify a paramter in the application in the same session and she can't reconnect again, that i thing.
Thanks
 

HEYTHEM 11/06/2007 08:35

Salut tt le monde, c'est très bon javabean mais il existe un bug que j'ai pas pu le resoudre.
Il consiste à la facon que la forme de CHAT réagit avec le SOCKET en effet lorsque je lance la premiere fois le chat il se connecte sur le port 4450 mais lorsque je quitte cette forme pour aller sur une autre et je retourne lancer de nouveau le chat la connexion ne s'établie pas et reste sur le message OPEN PORT.... sans faire de connection. Alors je doit quitter toute l'application pour la relancer de nouveau et rebelotte...
C'est quoi le problème??

Oracle Forms community 11/06/2007 10:30

Bonjour,Ceci est un site international. Merci donc de vous exprimer en Anglais.Regardez le code derrière le bouton "Connexion". On commence d'abord par se déconnecter:Set_Custom_Property( 'BL.BEAN', 1, 'STOP_SERVER', '' ) ;    Francois