tcpTest continued
This commit is contained in:
parent
497f66892a
commit
28ee8061ff
@ -14,23 +14,40 @@
|
||||
|
||||
const uint8_t TCPTEST_SOCK;
|
||||
|
||||
uint8_t remoteAddr[] = { 172, 16, 3, 31 };
|
||||
uint16_ remotePort = 5000;
|
||||
|
||||
void tcpTestHandler(void *handle) {
|
||||
static bool socketInitialized = false;
|
||||
static uint8_t state = 0;
|
||||
int8_t res = 0;
|
||||
|
||||
|
||||
if (isNetworkAvailable()) {
|
||||
if (! socketInitialized) {
|
||||
switch (state) {
|
||||
case 0:
|
||||
coloredMsg(LOG_YELLOW, "tth, initializing socket");
|
||||
|
||||
int8_t res = socket(TCPTEST_SOCK, Sn_MR_TCP, 12345, SF_IO_NONBLOCK);
|
||||
res = socket(TCPTEST_SOCK, Sn_MR_TCP, 12345, SF_IO_NONBLOCK);
|
||||
coloredMsg(LOG_YELLOW, "tth, socket returns %d", res);
|
||||
|
||||
if (res == TCPTEST_SOCK) {
|
||||
coloredMsg(LOG_YELLOW, "tth, socket is initialized");
|
||||
socketInitialized = true;
|
||||
state = 1;
|
||||
}
|
||||
} else {
|
||||
// coloredMsg(LOG_YELLOW, "tth, doing something useful with the socket");
|
||||
break;
|
||||
case 1:
|
||||
coloredMsg(LOG_YELLOW, "tth, connecting");
|
||||
|
||||
res = connect(TCPTEST_SOCK, remoteAddr, remotePort);
|
||||
coloredMsg(LOG_YELLOW, "tth, connect returns %d", res);
|
||||
|
||||
state = 255;
|
||||
|
||||
break;
|
||||
case 255:
|
||||
coloredMsg(LOG_YELLOW, "tth, error state, will stop here");
|
||||
schDel(tcpTestHandler, NULL);
|
||||
break;
|
||||
}
|
||||
} else {
|
||||
coloredMsg(LOG_YELLOW, "tth, network not yet ready");
|
||||
|
Loading…
x
Reference in New Issue
Block a user