This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

network cable is disconnected for a moment

why it can not access the destination Host when the network cable is disconnected for a moment and later this connected again?

//----------------------------------------------------------------------------
// Thread 'Server': BSD Server socket process
//----------------------------------------------------------------------------
static void Server (void const *arg) { SOCKADDR_IN addr; int sock, sd, res; int type = (int)arg; char dbuf[4];

while (1) { sock = socket (AF_INET, type, 0); addr.sin_port = htons(PORT_NUM); addr.sin_family = PF_INET; addr.sin_addr.s_addr = INADDR_ANY; bind (sock, (SOCKADDR *)&addr, sizeof(addr)); if (type == SOCK_STREAM) { listen (sock, 1); sd = accept (sock, NULL, NULL); closesocket (sock); sock = sd; } while (1) { res = recv (sock, dbuf, sizeof (dbuf), 0); if (res <= 0) { break; } if (dbuf[0] == BLINKLED) { LED_Out (dbuf[1]); } } closesocket (sock); }
}

Parents
  • This is example code:

    //----------------------------------------------------------------------------
    // Thread 'Server': BSD Server socket process
    //----------------------------------------------------------------------------

    static void Server (void const *arg) {

    SOCKADDR_IN addr;

    int sock, sd, res;

    int type = (int)arg;

    char dbuf[4];

    while (1) {

    sock = socket (AF_INET, type, 0);

    addr.sin_port = htons(PORT_NUM);

    addr.sin_family = PF_INET;

    addr.sin_addr.s_addr = INADDR_ANY;

    bind (sock, (SOCKADDR *)&addr, sizeof(addr));

    if (type == SOCK_STREAM) {

    listen (sock, 1);

    sd = accept (sock, NULL, NULL);

    closesocket (sock);

    sock = sd;

    }

    while (1) {

    res = recv (sock, dbuf, sizeof (dbuf), 0);

    if (res <= 0) {

    break;

    }

    if (dbuf[0] == BLINKLED) {

    LED_Out (dbuf[1]);

    }

    }

    closesocket (sock);

    }

    }

Reply
  • This is example code:

    //----------------------------------------------------------------------------
    // Thread 'Server': BSD Server socket process
    //----------------------------------------------------------------------------

    static void Server (void const *arg) {

    SOCKADDR_IN addr;

    int sock, sd, res;

    int type = (int)arg;

    char dbuf[4];

    while (1) {

    sock = socket (AF_INET, type, 0);

    addr.sin_port = htons(PORT_NUM);

    addr.sin_family = PF_INET;

    addr.sin_addr.s_addr = INADDR_ANY;

    bind (sock, (SOCKADDR *)&addr, sizeof(addr));

    if (type == SOCK_STREAM) {

    listen (sock, 1);

    sd = accept (sock, NULL, NULL);

    closesocket (sock);

    sock = sd;

    }

    while (1) {

    res = recv (sock, dbuf, sizeof (dbuf), 0);

    if (res <= 0) {

    break;

    }

    if (dbuf[0] == BLINKLED) {

    LED_Out (dbuf[1]);

    }

    }

    closesocket (sock);

    }

    }

Children