Using tiray. SMS
...
Tiray. SMS. cmpp30 m_cmpp = new tiray. SMS. cmpp30 ();
...
// Start CMPP
M_cmpp = new cmpp30 (txt_cmusername.text.trim (), forward (), txt_cmserveraddress.text.trim (), convert. toint32 (txt_cmserverport.text.trim ()));
M_cmpp.smsstatechanged + = new smseventhandler (oncmpp); // defines the event processing function
M_cmpp.startthread ();
...
// Terminate CMPP
M_cmpp.endthread ();
...
// Mobile SMS gateway event (asynchronous processing)
Protected void oncmpp (Object sender, smseventargs E)
{
Smsasyncevent AE = new smsasyncevent (processcmppevent );
Iasyncresult AR = NULL;
AR = AE. begininvoke (E, new asynccallback (cmppasynceventcallback), AE );
}
// Asynchronous event processing function
Protected void processcmppevent (smseventargs E)
{
String strstate = string. empty;
If (E. State = sms_state.deliver)
{
Cmpp_deliver deliver = (cmpp_deliver) E. Data;
...
}
Else if (E. State = sms_state.deliver_response)
{
Cmpp_deliver_resp resp = (cmpp_deliver_resp) E. Data;
...
}
Else if (E. State = sms_state.report)
{
Cmpp_deliver deliver = (cmpp_deliver) E. Data;
Cmpp_report report = deliver. getreport ();
...
}
Else if (E. State = sms_state.submit)
{
Cmpp_submit submit = (cmpp_submit) E. Data;
...
}
Else if (E. State = sms_state.submit_response)
{
Cmpp_submit_resp resp = (cmpp_submit_resp) E. Data;
...
}
Else if (E. State = sms_state.active_test)
{
...
}
Else if (E. State = sms_state.active_test_response)
{
Cmpp_active_test_resp resp = (cmpp_active_test_resp) E. Data;
...
}
Else if (E. State = sms_state.sp_connect)
{
Cmpp_connect_resp resp = (cmpp_connect_resp) E. Data;
...
}
Else if (E. State = sms_state.sp_disconnect)
{
...
}
Else if (E. State = sms_state.deliver_error)
{
...
}
Else if (E. State = sms_state.deliver_response_error)
{
...
}
Else if (E. State = sms_state.submit_error)
{
...
}
Else if (E. State = sms_state.submit_response_error)
{
...
}
Else if (E. State = sms_state.active_test_error)
{
...
}
Else if (E. State = sms_state.active_test_response_error)
{
...
}
Else if (E. State = sms_state.sp_connect_error)
{
...
}
Else if (E. State = sms_state.sp_disconnect_error)
{
...
}
}
// Asynchronous Event Callback Function
Private void cmppasynceventcallback (iasyncresult AR)
{
Smsasyncevent AE = (smsasyncevent) Ar. asyncstate;
AE. endinvoke (AR );
}
// Asynchronous short message sending
Cmppasyncsubmit S = new cmppasyncsubmit (m_cmpp.submit );
Iasyncresult AR = NULL;
String [] destinations = new string [destinationcount];
For (INT I = 0; I <destinationcount; I ++)
Strdest [I] = destination [I]. tostring ();
AR = S. begininvoke (message, destinations, source, serviceid, coding. GBK, true, (byte) tiray. SMS. fee_user_type.destination, (byte) tiray. SMS. fee_type.one, callback, source, linkid, new asynccallback (cmppasyncsubmitcallback), S );
...
// Callback function for asynchronous sending
Private void cmppasyncsubmitcallback (iasyncresult AR)
{
Cmppasyncsubmit S = (cmppasyncsubmit) Ar. asyncstate;
S. endinvoke (AR );
}
[End]