i'm trying to make a internet connection in a C program using Winsock. I found a great tut (Programming Windows TCP Sockets in C++ for the Beginner - CodeProject) but everything did not work as aspected. I have a winsock error n.o. 10049. When I search for this i see this : "The requested address is not valid in its context."
when I try to set up a loopback connection it gives no errors, but doesn't work either: he always think that there is a connectioncall (other words: the program doesn't "hang"). What am I doing wrong?
here is the server code:
int ListenOnPort(int portno);
printf("errorcode is %d", errorcode);
//LISTENONPORT – Listens on a specified port for incoming connections
int ListenOnPort(int portno)
int error = WSAStartup (0x0202, &w); // Fill in WSA info
return 50; //For some reason we couldn't start Winsock
if (w.wVersion != 0x0202) //Wrong Winsock version?
SOCKADDR_IN addr; // The address structure for a TCP socket
addr.sin_family = AF_INET; // Address family
addr.sin_port = htons (portno); // Assign port to this socket
//Accept a connection from any IP using INADDR_ANY
//You could pass inet_addr("0.0.0.0") instead to accomplish the
//same thing. If you want only to watch for a connection from a
//specific IP, specify that //instead.
addr.sin_addr.s_addr = inet_addr("127.0.0.1");
s = socket (AF_INET, SOCK_STREAM, IPPROTO_TCP); // Create socket
if (s == INVALID_SOCKET)
return 52; //Don't continue if we couldn't create a //socket!!
if (bind(s, (LPSOCKADDR)&addr, sizeof(addr)) == SOCKET_ERROR)
wprintf(L"bind failed with error %u\n", WSAGetLastError());
//We couldn't bind (this will happen if you try to bind to the same
//socket more than once)
//Now we can start listening (allowing as many connections as possible to
//be made at the same time using SOMAXCONN). You could specify any
//integer value equal to or lesser than SOMAXCONN instead for custom
//purposes). The function will not //return until a connection request is
//Don't forget to clean up with CloseConnection()!
EDIT: when I change the IPaddres to 192.168.0.28 I get this error.