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. my programm is not accepting connections

my programm is not accepting connections

Scheduled Pinned Locked Moved C / C++ / MFC
sysadminquestion
3 Posts 2 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.
  • W Offline
    W Offline
    willempipi
    wrote on last edited by
    #1

    the socket has been bind but my server is still not listning to my port, it just gives a INVALID_SOCKET. UINT ServerThread(LPVOID Param) { SOCKET server; WSADATA wsaData; sockaddr_in local; ServerStart = TRUE; int wsaret = WSAStartup(0x101, &wsaData); if (wsaret != 0) { return 0; } local.sin_family = AF_INET; local.sin_addr.s_addr = INADDR_ANY; local.sin_port = htons((u_short)20248); server=socket(AF_INET,SOCK_STREAM,0); if(server==INVALID_SOCKET) { AfxMessageBox("server invalid socket"); return 0; } if (bind(server, (sockaddr*)&local, sizeof(local)) == SOCKET_ERROR) { AfxMessageBox("Binden van socket mislukt"); return 0; } SOCKET client; sockaddr_in from; int fromlen = sizeof(from); AfxMessageBox("Server gestart"); char temp[512]; while(ServerStart == TRUE) { client = accept(server, (struct sockaddr*)&from, &fromlen); if (client != INVALID_SOCKET) { AfxMessageBox("accept"); sprintf(temp, "Your IP is %s\r\n", inet_ntoa(from.sin_addr)); send(client, temp, strlen(temp), 0); closesocket(client); } else { AfxMessageBox("invalid socket"); } } AfxMessageBox("Server Afgesloten"); closesocket(server); WSACleanup(); return 0; } what am i doing wrong? the programm keep giving the message: " invalid socket "

    W S 2 Replies Last reply
    0
    • W willempipi

      the socket has been bind but my server is still not listning to my port, it just gives a INVALID_SOCKET. UINT ServerThread(LPVOID Param) { SOCKET server; WSADATA wsaData; sockaddr_in local; ServerStart = TRUE; int wsaret = WSAStartup(0x101, &wsaData); if (wsaret != 0) { return 0; } local.sin_family = AF_INET; local.sin_addr.s_addr = INADDR_ANY; local.sin_port = htons((u_short)20248); server=socket(AF_INET,SOCK_STREAM,0); if(server==INVALID_SOCKET) { AfxMessageBox("server invalid socket"); return 0; } if (bind(server, (sockaddr*)&local, sizeof(local)) == SOCKET_ERROR) { AfxMessageBox("Binden van socket mislukt"); return 0; } SOCKET client; sockaddr_in from; int fromlen = sizeof(from); AfxMessageBox("Server gestart"); char temp[512]; while(ServerStart == TRUE) { client = accept(server, (struct sockaddr*)&from, &fromlen); if (client != INVALID_SOCKET) { AfxMessageBox("accept"); sprintf(temp, "Your IP is %s\r\n", inet_ntoa(from.sin_addr)); send(client, temp, strlen(temp), 0); closesocket(client); } else { AfxMessageBox("invalid socket"); } } AfxMessageBox("Server Afgesloten"); closesocket(server); WSACleanup(); return 0; } what am i doing wrong? the programm keep giving the message: " invalid socket "

      W Offline
      W Offline
      willempipi
      wrote on last edited by
      #2

      solution: changed the opening of de server connection, it works now...

      1 Reply Last reply
      0
      • W willempipi

        the socket has been bind but my server is still not listning to my port, it just gives a INVALID_SOCKET. UINT ServerThread(LPVOID Param) { SOCKET server; WSADATA wsaData; sockaddr_in local; ServerStart = TRUE; int wsaret = WSAStartup(0x101, &wsaData); if (wsaret != 0) { return 0; } local.sin_family = AF_INET; local.sin_addr.s_addr = INADDR_ANY; local.sin_port = htons((u_short)20248); server=socket(AF_INET,SOCK_STREAM,0); if(server==INVALID_SOCKET) { AfxMessageBox("server invalid socket"); return 0; } if (bind(server, (sockaddr*)&local, sizeof(local)) == SOCKET_ERROR) { AfxMessageBox("Binden van socket mislukt"); return 0; } SOCKET client; sockaddr_in from; int fromlen = sizeof(from); AfxMessageBox("Server gestart"); char temp[512]; while(ServerStart == TRUE) { client = accept(server, (struct sockaddr*)&from, &fromlen); if (client != INVALID_SOCKET) { AfxMessageBox("accept"); sprintf(temp, "Your IP is %s\r\n", inet_ntoa(from.sin_addr)); send(client, temp, strlen(temp), 0); closesocket(client); } else { AfxMessageBox("invalid socket"); } } AfxMessageBox("Server Afgesloten"); closesocket(server); WSACleanup(); return 0; } what am i doing wrong? the programm keep giving the message: " invalid socket "

        S Offline
        S Offline
        SatyaDY
        wrote on last edited by
        #3

        Hi, Use WSAGetLastError(), instead of printing some message. From the error index it's easy to find out what went wrong. :) Satya

        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