Hi, all! When form is closed it not close connection, and when you run again chat form it cannot to open connection to receive message from server. What I do for fix this problem? In form triggers WHEN-WINDOW-CLOSED: Deconnexion; WHEN-TIMER-EXPIRED: IF GET_APPLICATION_PROPERTY(TIMER_NAME) = 'EXIT_TIMER' THEN EXIT_FORM(); END IF; BL.EXIT BUtton WHEN-BUTTON-PRESSED: Deconnexion; New procedure: PROCEDURE SEND_STATUS( PC$Text In Varchar2 ) IS /* I used this function any time when I need inform users for chat's status */ BEGIN :BL.STATUS := TO_CHAR(SYSDATE, 'HH24:MI')||' '|| PC$Text || CHR(10) || :BL.STATUS; END; PROCEDURE Deconnexion IS EXIT_TIMER TIMER; BEGIN -- Deconnexion -- IF :Global.Chat_Status = '0' THEN SEND_STATUS( 'Disconnecting ... Please Wait.' ); Set_Custom_Property( 'BL.BEAN', 1, 'STOP_SERVER', '' ) ; -- wait for two seconds when i receive msg from server, in BL.BEAN custom event EXIT_TIMER := CREATE_TIMER( 'EXIT_TIMER', 2000, NO_REPEAT ); GO_BLOCK('CHATERS'); Set_Item_Property( 'BL.EXIT', ENABLED, PROPERTY_FALSE ) ; Set_Item_Property( 'BL.START', ENABLED, PROPERTY_FALSE ) ; -- I remove BL.START from canvas, USER automaticly logon, and exit when close form or push button :Global.Chat_Status := '1' ; END IF; END; server.java public void doStop() { if (sock != null) { try { sock.close(); } catch (IOException e) { System.err.println("Error : unable close connection"); } finally { sock = null; System.out.println("ServerSocket was closed"); } } } chat.java public boolean setProperty(ID property, Object value) { ... cut .... else if (property == stopServer) { if (bOk) { SendMessage("[SocketServerClose]"); server.doStop(); stopThread(); bOk = false; } return true; ... cut .... } That's all folks
It just needs to put a Deconnexion ; instruction in the POST-FORM trigger.
S
Surger
07/12/2006 08:39
Good work!But the browser is eating full time of processorI change chat.java: public void run() { Thread theThread = Thread.currentThread(); while (runner == theThread) {// well we need sleep to release processor for do any thing else try { theThread.sleep(1000); } catch (InterruptedException e) { System.err.println("Error : " + e); e.printStackTrace(); } // tell Forms that a message is incoming if (bMsg) { System.out.println("Sendmessage=" + sMessage); SendMessage(sMessage); bMsg = false; if (sMessage.equalsIgnoreCase("BYE.")) stopThread(); } } }