Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 532001
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T09:21:34+00:00 2026-05-13T09:21:34+00:00

I am testing out a Socket Server application in c and I am getting

  • 0

I am testing out a Socket Server application in c and I am getting an error on the bind function with code 10038. I looked this up and MSDN says it means:

An operation was attempted on something that is not a socket. Either the socket handle parameter did not reference a valid socket, or for select, a member of an fd_set was not valid.

Here is the code:

// I have the correct include files such as include , but stackoverflow displays it weird when i put #include winsock2.h

int main()
{
WSADATA         wsaData;
SOCKET          ListeningSocket;
SOCKET          NewConnection;
SOCKADDR_IN     ServerAddr;
int             Port = 5150;


if(WSAStartup(MAKEWORD(2,2),&wsaData) != 0)
{
    printf("Server: WSAStartup failed with error %ld\n",WSAGetLastError());
    return -1;
}
else
{
        printf("Server: The Winsock dll found!\n");
        printf("Server: The current status is: %s.\n",wsaData.szSystemStatus);
}

if(LOBYTE(wsaData.wVersion) != 2 || HIBYTE(wsaData.wVersion) != 2)
{
    printf("Server: The dll do not support Winsock version 
           %u.%u!\n",LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion));
    WSACleanup();
    return -1;
}
else
{
    printf("Server: The dll supports the Winsock version %u.%u!\n",LOBYTE(wsaData.wVersion),HIBYTE(wsaData.wVersion));
    printf("Server: The highest version this dll can support: %u.%u\n",LOBYTE(wsaData.wHighVersion),HIBYTE(wsaData.wHighVersion));
}

ListeningSocket == socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);

if(ListeningSocket == INVALID_SOCKET)
{
    printf("Server: Error at socket(), error code: %ld\n",WSAGetLastError());
    WSACleanup();
    return -1;
}
else
    printf("Server: socket() is OK!\n");

ServerAddr.sin_family = AF_INET;
ServerAddr.sin_port = htons(Port);
ServerAddr.sin_addr.s_addr = htonl(INADDR_ANY);

if(bind(ListeningSocket, (SOCKADDR *)&ServerAddr,sizeof(ServerAddr)) == SOCKET_ERROR)
{

    printf("Server: bind() failed! Error code: %ld.\n",WSAGetLastError());
    closesocket(ListeningSocket);
    WSACleanup();
    return -1;
}
else
    printf("Server: bind() is OK!\n");

if(listen(ListeningSocket,5) == SOCKET_ERROR)
{
      printf("Server: listen(): Error listening on socket %ld.\n", WSAGetLastError());
      closesocket(ListeningSocket);
      WSACleanup();
      return -1;
 }
 else
      printf("Server: listen() is OK, I'm waiting for connections...\n");

 printf("Server: accept() is ready...\n");


 while(1)
 {
      NewConnection = SOCKET_ERROR;

      while(NewConnection == SOCKET_ERROR)
      {
          NewConnection = accept(ListeningSocket, NULL, NULL);
      }

      printf("Server: accept() is OK...\n");
      printf("Server: Client connected, ready for receiving and sending data...\n");

      ListeningSocket = NewConnection;

      break;
 }

 if(closesocket(NewConnection) != 0)
     printf("Server: Cannot close \"NewConnection\" socket. Error code: %ld\n", 
            WSAGetLastError());
 else
      printf("Server: Closing \"NewConnection\" socket...\n");

 if(WSACleanup() != 0)
      printf("Server: WSACleanup() failed! Error code: %ld\n", WSAGetLastError());
 else
      printf("Server: WSACleanup() is OK...\n");


 return 0;

}

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-13T09:21:35+00:00Added an answer on May 13, 2026 at 9:21 am

    I just got it, I put == for

    ListeningSocket == socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    

    instea of =

    ListeningSocket = socket(AF_INET,SOCK_STREAM,IPPROTO_TCP);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 372k
  • Answers 372k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer How about: TRANSFORM First(Sweetness.Sweetness) AS FirstOfSweetness SELECT Fruit.FruitName FROM (Sweetness… May 14, 2026 at 7:18 pm
  • Editorial Team
    Editorial Team added an answer Plugin creates invisible file input on top of the button… May 14, 2026 at 7:18 pm
  • Editorial Team
    Editorial Team added an answer One of the solutions I found for this rounding border… May 14, 2026 at 7:18 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.