Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
Next revision
Previous revision
Last revision Both sides next revision
sdk:tcp2sms [2015/07/03 08:55]
fachet
sdk:tcp2sms [2017/10/23 16:44]
fachet
Line 2: Line 2:
 /* DESC: This script send a SMS received by a TCP message "<​number>:<​text>"​ /* DESC: This script send a SMS received by a TCP message "<​number>:<​text>"​
  * Don't forget to configure and enable the SMS service first  * Don't forget to configure and enable the SMS service first
 + * The number format is international e.g. +4912345678
 + *
  * Copyright (C) 2012 NetModule AG, Switzerland  * Copyright (C) 2012 NetModule AG, Switzerland
  */  */
-port = 2000; 
  
-if ((s socket(AF_INET,​ SOCK_STREAM,​ IPPROTO_TCP)) ​ < 0) exit(1); +PORT 2000;
-if (bind(s, port, ""​) == -1) exit(2); +
-if (listen(s, 1) == -1) exit(3);+
  
-for(;;) { +if ((s socket(AF_INET, SOCK_STREAM,​ IPPROTO_TCP)) < 0)  
-    ​if (accept(s)) +  exit(1); 
-        for(;;{ +if (bind(sPORT, ""​) == -1) 
-            if ((r = select(c10)) == - 1) exit(4); +  ​exit(2); 
-            if (r == 0) continue; +if (listen(s, 1) =-1)  
-            m = recv(c)+  exit(3);
-            if (p strchr(m, ":"​)) +
-                if (nb_sms_send(left(m,​ p), right(m, strlen(m) - p - 1))+
-                   send(s, "​Spooled\n"​); +
-                else +
-                   ​send(s,​ "​Error\n"​);​ +
-+
-}+
  
 +while (true) {
 +  if (c = accept(s)) {
 +    while (true) {
 +      if ((r = select(c, 10)) == - 1) 
 +        exit(4);
 +      if (r == 0) 
 +        continue;
 +      m = recv(c);
 +      if (p = strchr(m, ":"​))
 +        if (nb_sms_send(left(m,​ p), right(m, strlen(m) - p - 1)))
 +          send(c, "​Spooled\n"​);​
 +        else
 +          send(c, "​Error\n"​);​
 +    }
 +  }
 +}
 +/* not reached */
 </​code>​ </​code>​