|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
|
Announcements
Chapters
Services
Feature Zones
|
IntroductionSMS client and server is an application software which is used for sending and receiving messages(SMS). It listens for incoming messages to arrive, processes the message if it's in a valid format. Note the processing of arrived messages depends on the application which will be discussed later. I am going to explain the following things:
I have used the Using the code1) Communication Port Settings
public class CommSetting
{
public static int Comm_Port=0;
public static Int64 Comm_BaudRate=0;
public static Int64 Comm_TimeOut=0;
public static GsmCommMain comm;
public CommSetting()
{
//
// TODO: Add constructor logic here
//
}
}
Before creating a The The following block of code will try to connect. If any problem occurs "Phone not connected" message appears and you can either retry by clicking on the Retry button or else Cancel. GsmCommMain comm = new GsmCommMain(port, baudRate, timeout);
try
{
comm.Open();
while (!comm.IsConnected())
{
Cursor.Current = Cursors.Default;
if (MessageBox.Show(this, "No phone connected.",
"Connection setup", MessageBoxButtons.RetryCancel,
MessageBoxIcon.Exclamation) == DialogResult.Cancel)
{
comm.Close();
return;
}
Cursor.Current = Cursors.WaitCursor;
}
// Close Comm port connection (Since it's just for testing
// connection)
comm.Close();
}
catch(Exception ex)
{
MessageBox.Show(this, "Connection error: " + ex.Message,
"Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Warning);
return;
}
// display message if connection is a success.
MessageBox.Show(this, "Successfully connected to the phone.",
"Connection setup", MessageBoxButtons.OK, MessageBoxIcon.Information);
2) Receive Incoming MessageWe are going to register the following events for
private void MessageReceived()
{
Cursor.Current = Cursors.WaitCursor;
string storage = GetMessageStorage();
DecodedShortMessage[] messages = CommSetting.comm.ReadMessages
(PhoneMessageStatus.ReceivedUnread, storage);
foreach(DecodedShortMessage message in messages)
{
Output(string.Format("Message status = {0},
Location = {1}/{2}",
StatusToString(message.Status),
message.Storage, message.Index));
ShowMessage(message.Data);
Output("");
}
Output(string.Format("{0,9} messages read.",
messages.Length.ToString()));
Output("");
}
The above code will read all unread messages from SIM memory. The method 3) Send Message
You can send an SMS by keying in the destination phone number and text message. If you want to send a message in your native language (Unicode), you need to check in Send as Unicode(UCS2). SmsSubmitPdu pdu = new SmsSubmitPdu
(txt_message.Text,txt_destination_numbers.Text,"");
An extended version of PDU is used when you are sending a message in Unicode. try
{
// Send an SMS message
SmsSubmitPdu pdu;
bool alert = chkAlert.Checked;
bool unicode = chkUnicode.Checked;
if (!alert && !unicode)
{
// The straightforward version
pdu = new SmsSubmitPdu
(txt_message.Text, txt_destination_numbers.Text,"");
}
else
{
// The extended version with dcs
byte dcs;
if (!alert && unicode)
dcs = DataCodingScheme.NoClass_16Bit;
else
if (alert && !unicode)
dcs = DataCodingScheme.Class0_7Bit;
else
if (alert && unicode)
dcs = DataCodingScheme.Class0_16Bit;
else
dcs = DataCodingScheme.NoClass_7Bit;
pdu = new SmsSubmitPdu
(txt_message.Text, txt_destination_numbers.Text, "", dcs);
}
// Send the same message multiple times if this is set
int times = chkMultipleTimes.Checked ?
int.Parse(txtSendTimes.Text) : 1;
// Send the message the specified number of times
for (int i=0;i<times;i++)
{
CommSetting.comm.SendMessage(pdu);
Output("Message {0} of {1} sent.", i+1, times);
Output("");
}
}
catch(Exception ex)
{
MessageBox.Show(ex.Message);
}
Cursor.Current = Cursors.Default;
4) Read All Messages
You can read all messages from the phone memory of SIM memory. Just click on "Read All Messages" button. The message details such as sender, date-time, text message will be displayed on the Data Grid. Create a new row for each read message, add to Data table and assign the Data table to datagrid's source private void BindGrid(SmsPdu pdu)
{
DataRow dr=dt.NewRow();
SmsDeliverPdu data = (SmsDeliverPdu)pdu;
dr[0]=data.OriginatingAddress.ToString();
dr[1]=data.SCTimestamp.ToString();
dr[2]=data.UserDataText;
dt.Rows.Add(dr);
dataGrid1.DataSource=dt;
}
The above code will read all unread messages from SIM memory. The method For received messageDecodedShortMessage[] messages =
CommSetting.comm.ReadMessages(PhoneMessageStatus.ReceivedUnread, storage);
For read all messagesDecodedShortMessage[] messages =
CommSetting.comm.ReadMessages(PhoneMessageStatus.All, storage);
5) Delete Messages (One or All)
All messages which are sent by the users will be stored in SIM memory and we are going to display them in the Data grid. We can delete a single message by specifying the message index number. We can delete all messages from SIM memory by clicking on "Delete All" button. Messages are deleted based on the index. Every message will be stored in memory with a unique index. The following code will delete a message based on index: // Delete the message with the specified index from storage
CommSetting.comm.DeleteMessage(index, storage);
To delete all messages from memory( SIM/Phone) // Delete all messages from phone memory
CommSetting.comm.DeleteMessages(DeleteScope.All, storage);
The
ApplicationsHere are some interesting applications where you can use and modify this software. 1) Pre paid ElectricityScenario (Customer)The customer has agreed for pre paid electricity recharges with the help of recharge coupons. The coupon is made available at shops. The customer will first buy the coupons from shops; every coupon consists of Coupon PIN which will be masked, the customer needs to scratch to view the PIN number. The customer will send an SMS to the SMS Server with a specified message format for recharging. Message Format for Recharging: Scenario (Server Database)On the Server, the Database consists of Customer information along with his telephone number, there will a field named 2) AstrologyYou can implement as astrology software. The user will send an SMS with his zodiac sign. The SMS server will maintain an Astrology Database with zodiac sign and a text description which contains a message for the day. The Database is required to be updated daily for all zodiac signs. Message Format which will be used by the user to get message of the day: 3) Remote Controlling SystemWe can implement a remote controlling system, for example you need to:
You can send an SMS. The SMS server will listen and then process the message. Based on the message format sent by the user we can take action. ConclusionThis project wouldn't be completed unless I thank the Reference
|
||||||||||||||||||||||