Overblog Tous les blogs Top blogs Technologie & Science Tous les blogs Technologie & Science
Editer l'article Suivre ce blog Administration + Créer mon blog
MENU

This is a bunch of tips and techniques related to Oracle PL/SQL and Forms.

Publicité

Chat on Forms

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.

Publicité
Retour à l'accueil
Partager cet article
Repost0
Pour être informé des derniers articles, inscrivez vous :
Commenter cet article
M
The Java Bean sign had been expired, and there for The Java Bean is not running always, if I signed the application will I make sure that Java Bean will always Run ?
Répondre
S
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"<br /> Please help...<br /> Thanx
Répondre
M
Have you solve This ?
H
this is the messages of the  JAVA CONSOL <br /> Downloading to JAR cache<br /> RegisterWebUtil - Loading WebUtil Version 1.0.6<br /> Loading  from JAR cache<br /> Loading  from JAR cache<br /> Loading  from JAR cache<br /> Loading  from JAR cache<br /> Loading  from JAR cache<br /> proxyHost=null<br /> proxyPort=0<br /> connectMode=HTTP, native.<br /> Forms هو : 9.0.4.3<br /> ServerSocket is running    // for the first acces is oki but after nothing can connect<br /> Error : unable to create socket<br /> Error : unable to create socket
Répondre
O
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
H
Sorry francois for speaking french  i don't khnow that i must speak english.<br /> 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.<br /> 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.<br /> Thanks<br />  
Répondre
H
Salut tt le monde, c'est très bon javabean mais il existe un bug que j'ai pas pu le resoudre.<br /> 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...<br /> C'est quoi le problème??
Répondre
O
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