Socket example

Socket example

Socket example
#include <io> #include <read> #include <float> #include <string> #include <core> #include <write> #include <define> #include <socket> new ignition_state; // Variable new last_ignition_state = 0; // Variable new socketRx[1520]; // Array new socketTx[1520]; // Array public callback (sk) { switch(sk) { case Socket_data_received: // Socket data received callback event { ReadSocket(); // Go to ReadSocket() function } case Socket_closed: // Socket closed callback event { write_buf(SMS, 0, "+370611111XX", "Disconnected"); // Send SMS to "+370611111XX" with "Disconnected" message } } return 0; } ReadSocket() // ReadSocket() function { socket(READ, socketRx); // Read socket buffer into socketRx array if(strcmp(socketRx, "Hello", false, 5)==0) // Compare received message with "Hello" string { // If match do... socket(SEND, 2, "Hi"); // Send back message through socket } } main() { Delay(10000); // Delay 10 sec. if (socket(CREATE_UDP, "domain.com", 1234) == CONNECTED) // Connect to socket { // if connected do... socket(SEND, 13, "Connected !!!"); // Send message through socket } while(1) { Delay(30000); // Delay 30 sec. socket(SEND, "Ping"); // Send message through socket } }