java - How to submit SMSPP messages and receive delivery receipt at the same time without dropping any SMS -
i have jframe in java , have code in click action of button .when click it checks sql database , send messages gets , wait delivery reciept .message submitted fine report status not received .i can receive 1 , drop 1 .i receive report status first message , third , on . dont know if thread problem here code in button action:
private void connect_btnactionperformed(java.awt.event.actionevent evt) { if(jcheckbox1.isselected()) { remoteip=ip.gettext(); } else{ remoteip="127.0.0.1" ; } connect_btn.setenabled(false); interval=(string) time.getselecteditem(); timeinterval =integer.valueof(interval); threadonce=true; bind(); url="jdbc:sqlserver://"+remoteip+ " :1433;databasename=test;user=sa;password=11235813"; sql ="select * alarm_table flag=0"; new thread(new runnable() { @override public void run() { while(true) { con=null; pst=null; rs=null; try{ class.forname("com.microsoft.sqlserver.jdbc.sqlserverdriver"); con = drivermanager.getconnection(url); pst= con.preparestatement(sql); rs =pst.executequery(); while (rs.next()) { smppconnect(rs.getstring(2),rs.getstring(3),rs.getstring(4)); //thread.sleep(2000); if(sentcheck==1) { updatetable(rs.getint(1)); } } session.setmessagereceiverlistener(new messagereceiverlistener() { public void onacceptdeliversm(deliversm deliversm) throws processrequestexception { if (messagetype.smsc_del_receipt.containedin(deliversm.getesmclass())) { // delivery receipt try { deliveryreceipt delreceipt = deliversm.getshortmessageasdeliveryreceipt(); id = long.parselong(delreceipt.getid()) & 0xffffffff; messageid = long.tostring(id, 16).touppercase(); system.out.println("received '" +messageid+"' : " + delreceipt); val=delreceipt.getfinalstatus().value(); system.out.println(val+" "+messageid); updatetablestate(integer.tostring(val),messageid); } catch (invaliddeliveryreceiptexception e) { system.err.println("receive faild"); e.printstacktrace(); } }else { // regular short message system.out.println("receiving message : " + new string(deliversm.getshortmessage())); } // regular short message } public void onacceptalertnotification(alertnotification alertnotification) { system.out.println("onacceptalertnotification"); } public datasmresult onacceptdatasm(datasm datasm, session source) throws processrequestexception { system.out.println("onacceptdatasm"); return null; } }); system.out.println("finish!"); } catch(exception e) { joptionpane.showmessagedialog(null,e);} finally{ try {if(pst!=null) pst.close(); } catch (sqlexception ex) { logger.getlogger(login.class.getname()).log(level.severe, null, ex); } try { if(con!=null) con.close(); } catch (sqlexception ex) { logger.getlogger(login.class.getname()).log(level.severe, null, ex); } } try { thread.sleep(1000 * timeinterval); // time interval between check , } catch (interruptedexception ex) { logger.getlogger(login.class.getname()).log(level.severe, null, ex); } } } }).start(); }
Comments
Post a Comment