Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C / C++ / MFC
  4. how to detect server closed abnormally,

how to detect server closed abnormally,

Scheduled Pinned Locked Moved C / C++ / MFC
questionsysadminhelptutorialannouncement
1 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • J Offline
    J Offline
    Jetli Jerry
    wrote on last edited by
    #1

    hi all, I am having non-blocking TCP socket, trying to receive in a loop for requried bytes. I am disconnectiing server by removing n/w cable from m/c running server application. every time recv() fails with WSAWOULDBLOCK, why? How can i detect that server died abnormally at client end? recv() also not returning 0? following is code iMode = 1; // non-zero = non-blocking mode iResult = ioctlsocket(sockMain,FIONBIO,(u_long FAR*)&iMode); iDataGot=0; while ( iData2Recv >= iDataGot ) { // recv single byte at a time iResult = recv(sockMain,&chData,1,0); // if zero byte got or any other error if ( iResult == 0 ) { //never reach here break; } /* timeout scheme // check timeout period DWORD dwCur = GetTickCount(); if ( dwCur > dwTimeout ) { // timeout occured, so we failed break; } */ if ( iResult == SOCKET_ERROR ) { if ( WSAGetLastError() != WSAEWOULDBLOCK ) { // never reaches here break; } else { // always executed. continue; } } // we got something add into output string if ( iResult == 1 ) { // add data,update counter into string and break if all datalen is received. } client application calls receive() after 10sec and it timeouts after 10sec if no data arrived. I want eliminate later 10sec. and detect server has died. Thanks in advance.

    Jetli Constant Thing In World Is Change.

    1 Reply Last reply
    0
    Reply
    • Reply as topic
    Log in to reply
    • Oldest to Newest
    • Newest to Oldest
    • Most Votes


    • Login

    • Don't have an account? Register

    • Login or register to search.
    • First post
      Last post
    0
    • Categories
    • Recent
    • Tags
    • Popular
    • World
    • Users
    • Groups