I have 2 simple codes on Linux, cli.c and svr.c
Both client and server is run in daemon, and the socket is really established between each other. However, when I reboot the server(192.168.10.10), client could not feel this, it is still pending at the function recv, the socket is still established seen from netstat.Code:// -------------------cli.c----------------------------- int main() { int sock = socket(PF_INET, SOCK_STREAM, 0), csock; SOCKADDR_IN sin, csin; int csinsize = sizeof(csin), read; char buf[4096]; Logi(sock); sin.sin_family = PF_INET; sin.sin_port = htons(3000); sin.sin_addr.s_addr = inet_addr("192.168.10.10"); while (TRUE) { // csock = accept(sock, (PSOCKADDR) &csin, &csinsize); Logi(connect(sock, (PSOCKADDR) &sin, sizeof(sin))); while ((read = recv(sock, buf, 4096, 0)) > 0) { Log("read:"); Logi(read); } Log("Connect closed."); } return 0; } //-----------------svr.c-------------------------- int main() { int sock = socket(PF_INET, SOCK_STREAM, 0), csock; SOCKADDR_IN sin, csin; int csinsize = sizeof(csin), read; char buf[4096]; #ifdef DAEMON gLogfp = fopen("arpl", "w"); daemon(0, 0); #endif Logi(sock); sin.sin_family = PF_INET; sin.sin_port = htons(3000); sin.sin_addr.s_addr = htonl(INADDR_ANY); bzero(&sin.sin_zero, 8); Logi(bind(sock, (PSOCKADDR) &sin, sizeof(sin))); Logi(listen(sock, 10)); while (TRUE) { Logi(csock = accept(sock, (PSOCKADDR) &csin, &csinsize)); while ((read = recv(csock, buf, 4096, 0) > 0)) { Log("read"); Logi(read); } Log("Connect closed."); } return 0; }Can anyone give me a hint? Thanks.



LinkBack URL
About LinkBacks
Can anyone give me a hint? Thanks. 


