#include<iostream>  
#include<Winsock2.h>  
using namespace std;  
void main()  
{  
    WORD wVersionRequested;  
    WSADATA wsaData;  
    int err;  
    wVersionRequested = MAKEWORD( 2, 2 );  
    err = WSAStartup( wVersionRequested, &wsaData );  
    if ( err != 0 ) {  
        return;  
    } 
    if ( LOBYTE( wsaData.wVersion ) != 2 ||  
        HIBYTE( wsaData.wVersion ) != 2 ) {  
        WSACleanup( );  
        return;   
    }  
    SOCKET sockclient=socket(AF_INET,SOCK_STREAM,0);  
    SOCKADDR_IN addrclient;  
    addrclient.sin_addr.S_un.S_addr=inet_addr("127.0.0.1");//设置要连接的主机IP，这里用一台机做试验  
    addrclient.sin_family=AF_INET;  
    addrclient.sin_port=htons(6000);  
    connect(sockclient,(SOCKADDR*)&addrclient,sizeof(SOCKADDR));  
    char receiveBuf[100];  
    recv(sockclient,receiveBuf,100,0);  
    cout<<"receive from the server"<<receiveBuf<<endl;  
    send(sockclient,"hello,I am client",strlen("hello,I am client")+1,0);  
    closesocket(sockclient);  
    WSACleanup();  
}  