SMS sending for most users

I want to send SMS large number of users (4000 users), so I put the following cycle loop:

 protected int SendSMS(string url) { // Now to Send Data. StreamWriter writer = null; StringBuilder postData = new StringBuilder(); Uri myUri = new Uri(url); postData.Append(HttpUtility.ParseQueryString(myUri.Query).Get("Username")); postData.Append(HttpUtility.ParseQueryString(myUri.Query).Get("Password")); postData.Append(HttpUtility.ParseQueryString(myUri.Query).Get("Sender")); postData.Append(HttpUtility.ParseQueryString(myUri.Query).Get("Recipients")); postData.Append(HttpUtility.ParseQueryString(myUri.Query).Get("MessageData")); string webpageContent = string.Empty; byte[] byteArray = Encoding.UTF8.GetBytes(postData.ToString()); HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(url); webRequest.Method = "POST"; webRequest.ContentType = "application/x-www-form-urlencoded"; webRequest.ContentLength = webRequest.ContentLength = byteArray.Length; writer = new StreamWriter(webRequest.GetRequestStream()); try { using (Stream webpageStream = webRequest.GetRequestStream()) { webpageStream.Write(byteArray, 0, byteArray.Length); } using (HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse()) { using (StreamReader reader = new StreamReader(webResponse.GetResponseStream())) { webpageContent = reader.ReadToEnd(); //TODO:parse webpagecontent: iF response contains "OK" if (webpageContent.Contains("OK")) return 1; else return 0; } } //return 1; } catch (Exception ee) { ErrMapping.WriteLog(url); string error = ee.Message + "<br><br>Stack Trace : " + ee.StackTrace; ErrMapping.WriteLog(error); return -1; } } 

After a certain number of users, such as 65 users, no SMS was sent to other users and

I get the following exception:

 Error Message:Thread was being aborted.<br><br>Stack Trace : at System.Net.UnsafeNclNativeMethods.OSSOCK.recv(IntPtr socketHandle, Byte* pinnedBuffer, Int32 len, SocketFlags socketFlags) at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags, SocketError& errorCode) at System.Net.Sockets.Socket.Receive(Byte[] buffer, Int32 offset, Int32 size, SocketFlags socketFlags) at System.Net.Sockets.NetworkStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.PooledStream.Read(Byte[] buffer, Int32 offset, Int32 size) at System.Net.Connection.SyncRead(HttpWebRequest request, Boolean userRetrievedStream, Boolean probeRead) at System.Net.ConnectStream.ProcessWriteCallDone(ConnectionReturnResult returnResult) at System.Net.HttpWebRequest.CheckDeferredCallDone(ConnectStream stream) at System.Net.HttpWebRequest.GetResponse() at SendSMS_EmailUI.Frm_SMS_send.SendSMS(String url) 
+4
source share
8 answers

I created an SMS portal. What you described was also described in version 1.0 of my application. The solution was to have my SMS gateway give me access to Bulk SMS via HTTP. I could host up to 1000 recipients in XML format (or comma-delimited) and send to Bulk SMS Gateway. Since I am running a shared host, I have limited this to 500 addresses.

I have a cache / temporary storage / table in which I heavily load a large destination (up to 1,000,000), and the scheduler (by timer) sends each batch of 500 pieces every few seconds (repeatedly calling the script) until while messages are being sent. It works like a charm!

For personalized messages, I recommend that the client use my personalization desktop application before sending them to my SMS portal. Good luck.

PROCESS:

You will need three elements

  • script that receives a SendSMS request
  • script that sends SMS
  • Scheduler / Timer (Script / Host Service)

a. SMS sending request comes with

 a. The Message and Sender ID/ Sender GSM Number. b. The Destinations (as a comma delimited list). We'll assume 10,000 destinations 

B. Divide the destinations into 500 (any size you want) and register 500 destinations along with the message and SenderID in each line / INBOX record. Note: if you count 500 out of loops (10,000 loops), the script may shut down. The GSM numbers in my country are 13 digits. Therefore, I am doing a Sub String loop with a length of 500 (13 + 1) to get 500 destinations for each batch (20 loops). *

C. Call the script that sends the SMS. Sends the first 500 and marks the message as sent. You can add Time Sent. Launch Scheduler

D. The scheduler checks every 1.5 minutes if any unsent messages exist in INBOX and send it. If nothing, the scheduler stops. Thus, 10,000 messages are sent within 30 minutes

+6
source

IMHO, bulk operations that will be performed on behalf of the application can be easily performed using the following procedure

  • When sending bulk SMS, the details will be entered into the database table
  • The Windows service will constantly monitor this table for any updates.
  • When the Windows service finds new entries, it will take several entries, such as several hundred, and then submit them. Batch processing.
  • There may be a delay between subsequent requests.
  • This will allow you to track which positions have been failed, and also does not clog the server with voluminous data.

This is the most widely used approach.

Please provide your comments on this implementation.

+6
source

We are doing something similar to what saravan suggested for email messages, and we suspect that it will work with SMS.

Basically, the service that runs on our web server sends only x at a time, and there is a user delay y between each send. It can send two thousand minutes in less than ten minutes, without a CPU or bandwidth.

Some tips that were not in our original design should be kept in mind:

  • You have a way to manually stop all sending (see the next tip)

  • You have a convenient way to complete a specific message. If your code (or user) accidentally sends the same thing five times, you want to interrupt it quickly.

  • Use the configuration file for both numbers (x and y above) so you can configure it without redeploying. I think the y-delay is 50ms.

Before you decide to associate the same message with multiple recipients, make sure that smartphones cannot respond to everyone else in their package.

NTN

-Chris C.

+5
source

I suspect the problem is that since you are on the asp.net website and this is a long-term task in which it selects the answer.

this timeout is monitored in the web.config file and defaults to 110 seconds. Increase this to a much larger number and see if it starts to work.

  <system.web> <!-- 600 seconds = 10 minute timeout ---> <httpRuntime executionTimeout="600"/> </system.web> 

A better approach would be to use a separate thread and return progress updates to the user, although this would be more complex, but ultimately more reliable.

See Parallel.ForEach for an easy way to stream this process.

Msdn - httpRuntime documentation

+5
source

This does not answer your initial question, but is related to useful information. Once you solve this problem, you can strike another - telcos regularly blocks mass sent SMS messages as a way to suppress SMS spam. If you do this commercially, you will need to submit a short message to the Mobile Marketing Association and get their approval, which can take a considerable amount of time.

+5
source

check if your StreamWriter is configured

 using (StreamWriter writer = new StreamWriter(webRequest.GetRequestStream())) { } 
+3
source

Perhaps the buffer value is full, check it and set the maximum value in the web configuration file

+3
source

Perhaps you are making a web request too quickly: try slowing them down to eliminate synchronization problems, such as adding sleep:

  System.Threading.Thread.Sleep(1000); 

1000 ms = 1 sec - this is just a hint, you should try different values ​​to see if something has changed

+2
source

Source: https://habr.com/ru/post/1479905/


All Articles