socket tcp clinet most simple test program

// testsocketclient.cpp: Defines the entry point console application. 
// 

#include "stdafx.h" 

#include <winsock2.h> 
#include <stdio.h> 

#pragma the Comment (lib, "ws2_32.lib") 
void main () 
{ 
	// load the socket library, version negotiation 
	wVersionRequired WORD; 
	WSADATA WSADATA; 
	int ERR; 

	// request library 
	// WSAStartup (WORD wVersionRequired, WSADATA lpWSAData); 
	wVersionRequired MAKEWORD = (. 1,. 1); 
	ERR = WSAStartup (wVersionRequired, & WSADATA); 

	IF (! ERR = 0) 
	{ 
		is not equal to 0 // exit 
		return; 
	} 

	// the high and low bytes is not. 1 
	IF (LOBYTE (wsaData.wVersion) = || hibyte. 1 (wsaData.wVersion) =. 1!!) 
	{  
		WSACleanup () ;
		return; 
	}
	SOCKET sockClient = socket(AF_INET, SOCK_STREAM, 0);
	//设定服务器的地址信息
	SOCKADDR_IN addrSrv;
	addrSrv.sin_addr.S_un.S_addr = inet_addr("10.10.22.105");
	addrSrv.sin_family = AF_INET;
	addrSrv.sin_port = htons(9099);
	connect(sockClient, (SOCKADDR*)&addrSrv, sizeof(SOCKADDR));
    label:
	send(sockClient, "this is qiang ge", strlen("this is qiang ge") + 1, 0);
	while (1)
	{
	char recvBuf[100];
	recv(sockClient, recvBuf, 100, 0);
	printf("%s\n", recvBuf);
	int igoto = 0;
	scanf_s("%d", &igoto);
	if (igoto == 111)
	goto label;
	}
	closesocket(sockClient);
	WSACleanup();
	system("PAUSE");
}

  

Guess you like

Origin www.cnblogs.com/hshy/p/10949063.html