#include <stdio.h> 
#include <Winsock2.h> 
#include <process.h> 
#pragma comment (lib, "Ws2_32.lib") 

unsigned int __stdcall listeningThread(void *param)
{ 
	SOCKET sockSrv = socket(AF_INET, SOCK_STREAM, 0); 
	SOCKADDR_IN addrSrv; 

	addrSrv.sin_addr.S_un.S_addr = htonl(INADDR_ANY); 

	addrSrv.sin_family = AF_INET; 

	addrSrv.sin_port = htons((int)param); 



	int ret = bind(sockSrv, (SOCKADDR*) &addrSrv, sizeof(SOCKADDR)); 

	ret = listen(sockSrv, 5); 

	SOCKADDR_IN addrClient; 

	int len = sizeof(SOCKADDR); 

	while (1) 

	{ 

		SOCKET sockConn = accept(sockSrv, (SOCKADDR*) &addrClient, &len); 

		char sendBuf [] = "Hello World !"; 



		send(sockConn, sendBuf, strlen(sendBuf) + 1, 0); 

		char recvBuf[50]; 

		recv(sockConn, recvBuf, 50, 0); 

		printf("%s\n", recvBuf); 

		closesocket(sockConn); 

	} 

	return 0; 

} 

void main() 

{ 

	WORD wVersionRequested; 

	WSADATA wsaData; 

	int err; 



	wVersionRequested = MAKEWORD(2, 2); 



	err = WSAStartup(wVersionRequested, &wsaData); 

	if (err != 0) { 

		return; 

	} 



	_beginthreadex(NULL, 0, listeningThread, (void *) 8120, 0, NULL); 

	_beginthreadex(NULL, 0, listeningThread, (void *) 8121, 0, NULL); 

	Sleep(INFINITE); 

}