#include <stdio.h>
#include <WINSOCK2.H>
int main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1, 1 );
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return 1;
}
if ( LOBYTE( wsaData.wVersion ) != 1 ||
HIBYTE( wsaData.wVersion ) != 1 )
{
WSACleanup( );
return 1;
}
SOCKET socket_srv = socket(AF_INET,SOCK_STREAM,0);
struct sockaddr_in soc_addrs,soc_addrc ;
int soc_lens =
sizeof(sockaddr);
int soc_lenc =
sizeof(sockaddr);
char buffer[100];
soc_addrs.sin_addr.S_un.S_addr = inet_addr(
"127.0.0.1");
soc_addrs.sin_family = AF_INET;
soc_addrs.sin_port = htons(6000);
bind(socket_srv,(SOCKADDR *) &soc_addrs,soc_lenc);
listen(socket_srv,10);
while ( 1 )
{
SOCKET socket_client = accept(socket_srv,(SOCKADDR*)&soc_addrc,&soc_lenc);
recv(socket_client,buffer,100,0);
printf(
"%s\n",buffer);
closesocket( socket_client);
}
WSACleanup();
return 0;
}