This is a bunch of tips and techniques related to Oracle PL/SQL and Forms.
Purpose
Here is a Java bean that allows to chat on a Forms application

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
Set_Custom_Property('BLOCK.ITEM', 1, 'INIT_SERVER', 'port_number');
e.g. :
Set_Custom_Property( 'BL.BEAN', 1, 'INIT_SERVER', '4450' ) ;
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:
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.