client.cpp

来自「用c++编写的网络通信框架」· C++ 代码 · 共 42 行

CPP
42
字号
// client.cpp : Defines the entry point for the console application.
//

#include "stdafx.h"
#include "socket.h"

int main(int argc, char* argv[])
{
	xuwn::client c;

	while (TRUE)
	{
		if (!c.Init("127.0.0.1", 6666))
		{
			::printf("Init error code: %d\n", c.code);
			continue;
		}

		if (TRUE != c.Connect())
		{
			::printf("Connect error code: %d\n", c.code);
			continue;
		}

		for (int i = 0; i < 10000; i++)
		{
			char buf[128];
			::memset(buf, 0, sizeof(buf));

			::sprintf(buf, "0004%04d", i);

			int rc = ::send(c.GetSocket(), buf, ::strlen(buf), 0);

			Sleep(10);
		}

		c.Close();
	}
	return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?