TCP Service in Control6

Aus Ethersex_Wiki
(Weitergeleitet von TCP Listen)
Wechseln zu: Navigation, Suche

This example implenents a TCP service that listens on port 4444 and echoes any incoming data via syslog.

CONTROL_START

ON STARTUP DO
        TCP_LISTEN(4444, message_handler);
END

TCP_HANDLER(message_handler)
        for (;;) {
                if (uip_connected()) {
                        SYSLOG("connected");
                }
                if (uip_newdata ()) {
                        char *ptr = (char *) uip_appdata;
                        ptr[uip_len] = 0;
                        SYSLOG("%s", ptr)
                }
                PT_YIELD(pt);
        }
TCP_HANDLER_END();

CONTROL_END