This shows you the differences between two versions of the page.
| Both sides previous revisionPrevious revisionNext revision | Previous revision | ||
| sdk:tcp2sms [2015/07/03 08:55] – fachet | sdk:tcp2sms [2017/10/23 16:45] (current) – fachet | ||
|---|---|---|---|
| Line 2: | Line 2: | ||
| /* DESC: This script send a SMS received by a TCP message "< | /* DESC: This script send a SMS received by a TCP message "< | ||
| * Don't forget to configure and enable the SMS service first | * Don't forget to configure and enable the SMS service first | ||
| - | * Copyright (C) 2012 NetModule AG, Switzerland | + | * The number format is international e.g. +4912345678 |
| + | * | ||
| + | * Copyright (C) 2017 NetModule AG, Switzerland | ||
| */ | */ | ||
| - | port = 2000; | ||
| - | if ((s = socket(AF_INET, | + | PORT = 2000; |
| - | if (bind(s, port, "" | + | |
| - | if (listen(s, 1) == -1) exit(3); | + | |
| - | for(;;) { | + | if ((s = socket(AF_INET, SOCK_STREAM, |
| - | | + | exit(1); |
| - | for(;;) { | + | if (bind(s, PORT, "" |
| - | if ((r = select(c, 10)) == - 1) exit(4); | + | |
| - | if (r == 0) continue; | + | if (listen(s, 1) == -1) |
| - | m = recv(c); | + | exit(3); |
| - | if (p = strchr(m, ":" | + | |
| - | if (nb_sms_send(left(m, | + | |
| - | send(s, " | + | |
| - | else | + | |
| - | | + | |
| - | } | + | |
| - | } | + | |
| + | 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, | ||
| + | send(c, " | ||
| + | else | ||
| + | send(c, " | ||
| + | } | ||
| + | } | ||
| + | } | ||
| + | /* not reached */ | ||
| </ | </ | ||