![](http://static.javashuo.com/static/loading.gif)
#include <stdio.h>
![](http://static.javashuo.com/static/loading.gif)
#include <WINSOCK2.H>
int main()
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
WORD wVersionRequested;
![](http://static.javashuo.com/static/loading.gif)
WSADATA wsaData;
int err;
![](http://static.javashuo.com/static/loading.gif)
wVersionRequested = MAKEWORD( 1, 1 );
![](http://static.javashuo.com/static/loading.gif)
err = WSAStartup( wVersionRequested, &wsaData );
if ( err != 0 ) {
return 1;
![](http://static.javashuo.com/static/loading.gif)
}
if ( LOBYTE( wsaData.wVersion ) != 1 ||
![](http://static.javashuo.com/static/loading.gif)
HIBYTE( wsaData.wVersion ) != 1 )
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
WSACleanup( );
return 1;
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
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];
![](http://static.javashuo.com/static/loading.gif)
soc_addrs.sin_addr.S_un.S_addr = inet_addr(
"127.0.0.1");
![](http://static.javashuo.com/static/loading.gif)
soc_addrs.sin_family = AF_INET;
![](http://static.javashuo.com/static/loading.gif)
soc_addrs.sin_port = htons(6000);
![](http://static.javashuo.com/static/loading.gif)
bind(socket_srv,(SOCKADDR *) &soc_addrs,soc_lenc);
![](http://static.javashuo.com/static/loading.gif)
listen(socket_srv,10);
while ( 1 )
![](http://static.javashuo.com/static/loading.gif)
{
![](http://static.javashuo.com/static/loading.gif)
SOCKET socket_client = accept(socket_srv,(SOCKADDR*)&soc_addrc,&soc_lenc);
![](http://static.javashuo.com/static/loading.gif)
recv(socket_client,buffer,100,0);
![](http://static.javashuo.com/static/loading.gif)
printf(
"%s\n",buffer);
![](http://static.javashuo.com/static/loading.gif)
closesocket( socket_client);
![](http://static.javashuo.com/static/loading.gif)
}
![](http://static.javashuo.com/static/loading.gif)
WSACleanup();
return 0;
![](http://static.javashuo.com/static/loading.gif)
}