Click here to Skip to main content
15,920,005 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi all,

I have a sms gateway and i want to make an sms based command to serial port.

This is the idea :

1. my clients send sms to computer
2. The computer read the sms and based on the sms, make an custom USSD request to serial port
3. The computer send back the result from serial port to the clients

Here is the problem : many clients and many sms can be received by the computer in time but only one serial port to handle the request.

I need to make an application that make a "sms queue".
So when there are many sms received, it will go into the queue first, if the serial port is busy. If not, the serial port can right away process the sms.

The sms will be processed by FIFO order.

I know this will got to do with thread but i have no idea what is the perfect approach.
Please give a hint guys. Thank you.
Posted

1 solution

Look at creating a SMSMessage class and creating a single, static Queue<SMSMessage>[^] instance.
When you receive a message for TX, you create a new instance of an SMSMessage (including the info you need to respond to the client) and add it to the queue. You then have a background thread which retrieves a message from the queue and deals with it. It then used the info supplied to either respond directly, or pass the data to a separate thread to handle responding.

You will probably need to provide some locking to make the Queue thread safe - particularly if more than one thread will be adding to it.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900