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 check a socket is disconnected

How to check a socket is disconnected

Scheduled Pinned Locked Moved C / C++ / MFC
tutorialquestion
3 Posts 3 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.
  • S Offline
    S Offline
    Stefan 0
    wrote on last edited by
    #1

    I use raw Windows sockets. How to check whether the other side of the connection is closed? Thanks

    Y 1 Reply Last reply
    0
    • S Stefan 0

      I use raw Windows sockets. How to check whether the other side of the connection is closed? Thanks

      Y Offline
      Y Offline
      Yaron
      wrote on last edited by
      #2

      hi, i really need help in windows sockets, here is a function i wrote to connect to server: //----------- Function Implementation -------------------------------- bool ConnectToSocket() { if (WSAVERNOTSUPPORTED == WSAStartup(MAKEWORD(2,0),&WSAData)) { printf("WSAStartup Failed!\r\n"); return FALSE; }//end if else { printf("WSAStartup Success\r\n"); }//end else // construct socket sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if (sock == INVALID_SOCKET) { printf("Failed to construct socket!\r\n"); WSACleanup(); return FALSE; }//end if else { printf("Socket construction....Success\r\n"); }//end else // fill in socket address struct and connect to server sa.sin_family = AF_INET; sa.sin_port = 23; sa.sin_addr.S_un.S_addr = inet_addr("147.234.12.233"); int iErr = connect( sock,(SOCKADDR *)&sa,sizeof(sa)); return TRUE; } it doesn't seem to work ,i dont know why..... also how do i receive and send data???? please help me i am desperate! tnx a lot yaron

      R 1 Reply Last reply
      0
      • Y Yaron

        hi, i really need help in windows sockets, here is a function i wrote to connect to server: //----------- Function Implementation -------------------------------- bool ConnectToSocket() { if (WSAVERNOTSUPPORTED == WSAStartup(MAKEWORD(2,0),&WSAData)) { printf("WSAStartup Failed!\r\n"); return FALSE; }//end if else { printf("WSAStartup Success\r\n"); }//end else // construct socket sock = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP); if (sock == INVALID_SOCKET) { printf("Failed to construct socket!\r\n"); WSACleanup(); return FALSE; }//end if else { printf("Socket construction....Success\r\n"); }//end else // fill in socket address struct and connect to server sa.sin_family = AF_INET; sa.sin_port = 23; sa.sin_addr.S_un.S_addr = inet_addr("147.234.12.233"); int iErr = connect( sock,(SOCKADDR *)&sa,sizeof(sa)); return TRUE; } it doesn't seem to work ,i dont know why..... also how do i receive and send data???? please help me i am desperate! tnx a lot yaron

        R Offline
        R Offline
        RamiBuchnik
        wrote on last edited by
        #3

        there are some possebilities the first 1 is that the server is not up you don't check errors at all in the winsock.h there are list of errors you can take the error value (which is unsigned int)and send it to acheckerror function which does switch case over all the possebilities and then know more specific what is the problem any way good luck Rami Buchnik

        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