Dirty data

#include <WinSock2.h> #pragma comment(lib,"ws2_32.lib") #define PORT 5150 #define DATA_BUFSIZE 8192 int _tmain(int argc, _TCHAR* argv[]) { TCHAR szSendBuf[BUFSIZ]; TCHAR szRecvBuf[BUFSIZ]; DWORD dwTime = 10000; int iSendBytes = 0; int iRecvBytes = 0; WSADATA wsaData; SOCKET Listen; SOCKADDR_IN InternetAddr; WSAStartup(MAKEWORD(2,2), &wsaData); //----------------------------------------------- // Initialize Winsock //while (1) { if ((Listen = WSASocket(AF_INET, SOCK_STREAM, IPPROTO_TCP, NULL, 0, WSA_FLAG_OVERLAPPED)) == INVALID_SOCKET) { printf("WSASocket() failed with error %d/n", WSAGetLastError()); return WSAGetLastError(); } InternetAddr.sin_family = AF_INET; InternetAddr.sin_addr.s_addr = inet_addr("127.0.0.1"); InternetAddr.sin_port = htons(PORT); // Connect to server. ZeroMemory(szSendBuf,BUFSIZ); ZeroMemory(szRecvBuf,BUFSIZ); if (connect( Listen, (SOCKADDR*) &InternetAddr,sizeof(InternetAddr)) == SOCKET_ERROR) { printf( "Failed to connect at %d./n", WSAGetLastError()); WSACleanup(); return WSAGetLastError(); } for(;;) { sprintf_s(szSendBuf,"%d",dwTime); ++dwTime; for(int i = 0; i < 10; ++i) { iSendBytes = send(Listen,szSendBuf,strlen(szSendBuf),0); ::Sleep(1); } memset(szRecvBuf,0,BUFSIZ); iRecvBytes = recv(Listen,szRecvBuf,BUFSIZ,0); printf("%d byte recved---%s/n",iRecvBytes,szRecvBuf); } closesocket(Listen); ::Sleep(10); } WSACleanup(); return 0; }

你可能感兴趣的:(Dirty data)