??????????
#include <stdio.h>
#include <Winsock2.h>
#pragma comment( lib?? "ws2_32.lib" )
void main()
{
WORD wVersionRequested;
WSADATA wsaData;
int err;
wVersionRequested = MAKEWORD( 1?? 1 );//????????????λ????????????????λ???
err = WSAStartup( wVersionRequested?? &wsaData );//??winsock DLL??????????????????г??????Э??Winsock??汾???????????????????
if ( err != 0 )
{
return;
}
if ( LOBYTE( wsaData.wVersion ) != 1 ||HIBYTE( wsaData.wVersion ) != 1 )//LOBYTE???????16????????λ??HIBYTE???????16????????????????????????
{
WSACleanup( );
return;
}
for(int index=0;;index++)
{
SOCKET sockClient=socket(AF_INET??SOCK_STREAM??0);
SOCKADDR_IN addrClt;//????????????IP???
addrClt.sin_addr.S_un.S_addr=inet_addr("192.168.0.30");// inet_addr??IP??????????????????????????????
addrClt.sin_family=AF_INET;
addrClt.sin_port=htons(4000);
connect(sockClient??(SOCKADDR*)&addrClt??sizeof(SOCKADDR));//????????????????????????
char recvBuf[50];
recv(sockClient??recvBuf??50??0);
printf("my reply is : %s "??recvBuf);
char sendBuf[50];
sprintf(sendBuf??"%3d??"??index);
strcat(sendBuf??"server node of: yaopeng");
send(sockClient??sendBuf??strlen(sendBuf)+1??0);
closesocket(sockClient);
Sleep(2000);
}
WSACleanup();
}