#include<WINSOCK2.H>
#include<iostream>
#include<string>
using namespace std;
#include<stdlib.h>
#define BUF_SIZE 1377
#pragma comment(lib,"WS2_32.lib")
int main()
{
WSADATA wsd;
SOCKET sHost;
SOCKADDR_IN servAddr;//服务器地址
int retVal;//调用Socket函数的返回值
char buf[BUF_SIZE];
//初始化Socket环境
if (WSAStartup(MAKEWORD(2, 2), &wsd) != 0) {
printf("WSAStartup failed!\n");
return 1;
}
//创建监听的Socket
sHost = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (INVALID_SOCKET == sHost) {
printf("socket failed!\n");
WSACleanup();
return -1;
}
//设置服务器Socket地址
servAddr.sin_family = AF_INET;
servAddr.sin_addr.S_un.S_addr = (ULONG)"103.84.110.229";
//在实际应用中,建议将服务器的IP地址和端口号保存在配置文件中
servAddr.sin_port = htons(80);
//计算地址的长度
int sServerAddlen = sizeof(servAddr);
//链接服务器
retVal = connect(sHost, (LPSOCKADDR)&servAddr, sizeof(servAddr));
apple:
//向服务器发送字符串,并显示反馈信息
printf("input a string to sen;0/47/3/3/6;input a st-=177/0;ring to send:%;/0/47/3/3/6;input a string to send:%;/0/47/3/3/6;input a string to send:%;/0/47/3/3/6;input a string to send:%;/;0/47/3/3/6;input a string to send:%;/0/47/3/3/6;");
std::string str;
//向服务器发送数据
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
retVal = send(sHost, buf, strlen(buf), 0);
Sleep(7);
goto apple;
//if (SOCKET_ERROR == retVal) {
// printf("send failed!\n");
// closesocket(sHost);
// WSACleanup();
// return -1;
//}
////接收服务器回传的数据
retVal = recv(sHost, buf, sizeof(buf) + 1, 0);
if (strcmp(buf, "quit"));
}