Click here to Skip to main content
15,906,463 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

My environments:
- Windows XP, SP3
- VC++ 6.0

I written down just simple application as follow:
C++
#include <stdio.h>
#include "winsock2.h"
#include <windows.h>
#pragma comment(lib, "wininet.lib")
void main() {
  //----------------------
  // Initialize Winsock
  WSADATA wsaData;
  int iResult = WSAStartup(MAKEWORD(2,2), &wsaData);
  if (iResult != NO_ERROR)
    printf("Error at WSAStartup()\n");
  //----------------------
  // Create a SOCKET for listening for
  // incoming connection requests.
  SOCKET ListenSocket;
  ListenSocket = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
  if (ListenSocket == INVALID_SOCKET)
  {
    printf("Error at socket(): %ld\n", WSAGetLastError());
    WSACleanup();
    return;
  }
  //----------------------
  // The sockaddr_in structure specifies the address family,
  // IP address, and port for the socket that is being bound.
  sockaddr_in service;
  service.sin_family = AF_INET;
  service.sin_addr.s_addr = htonl( INADDR_ANY );
  service.sin_port = htons(10000);
  if (bind( ListenSocket, (SOCKADDR*) &service, sizeof(service)) == SOCKET_ERROR) {
    printf("bind() failed.\n");
    closesocket(ListenSocket);
    return;
  }
  //----------------------
  // Listen for incoming connection requests 
  // on the created socket
  if (listen( ListenSocket, SOMAXCONN ) == SOCKET_ERROR)
    printf("Error listening on socket.\n");
  printf("Listening on socket...\n");
  WSACleanup();
  return;
}

When execute this code, report "first-chance exception" error. But if change service.sin_addr.s_addr = htonl( INADDR_ANY ) to service.sin_addr.s_addr = inet_addr("127.0.0.1"); not report first-chance exception error.

Please advice me, if somebosy know.

Thanks,
Posted
Updated 30-Sep-10 1:13am
v2

1 solution

The information about the first-chance exception is strictly for the debugger. Normally it would turn into an unhanded exception if it becomes a second-chance exception and would terminate the application.

Microsoft blogger David Kline writes that a first-chance exception is very normal. (This would explain the exceptional high fail rate of Microsoft products). Have a look for yourself:

http://blogs.msdn.com/b/davidklinems/archive/2005/07/12/438061.asp[^]


Good luck!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900