Try this link:
http://msdn.microsoft.com/library/en-us/vcsample98/html/vcsmpsimple2.asp
Your basic steps are:
//From the platform SDK code...
#define DEFAULT_PORT "5001" // Default listening port
#define DEFAULT_PROTO SOCK_STREAM // Default to TCP protocol
#define DEFAULT_BUFFER_LEN 4096 // Default recv buffer length
// Load Winsock
if ((retval = WSAStartup(0x202,&wsaData)) != 0)
{
fprintf(stderr,"WSAStartup failed with error %d\n",retval);
WSACleanup();
return -1;
}
..
// Create the socket according to the parameters returned
server_sockets[socket_count] = socket(
addrptr->ai_family,
addrptr->ai_socktype,
addrptr->ai_protocol
);
if (server_sockets[socket_count] == INVALID_SOCKET)
{
fprintf(stderr, "socket failed: %d\n", WSAGetLastError());
goto cleanup;
}
// Bind the socket to the address returned
retval = bind(
server_sockets[socket_count],
addrptr->ai_addr,
addrptr->ai_addrlen
);
// If a TCP socket, call listen on it
if (addrptr->ai_socktype == SOCK_STREAM)
{
retval = listen(
server_sockets[socket_count],
7
);
if (retval == SOCKET_ERROR)
{
fprintf(stderr, "listen failed: %d\n", WSAGetLastError());
goto cleanup;
}
}
//And then you create a thread to handle the listen
server_threads[i] = CreateThread(
NULL,
0,
ServerThread,
(LPVOID)server_sockets[i],
0,
NULL
);
if (server_threads[i] == NULL)
{
fprintf(stderr, "CreateThread failed: %d\n", GetLastError());
goto cleanup;
}