⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 server.cpp

📁 用c++编写的网络通信框架
💻 CPP
字号:
// server.cpp : Defines the entry point for the console application.
//

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

int main(int argc, char* argv[])
{
	xuwn::server s;

	while (TRUE)
	{
		if (!s.Init("127.0.0.1", 6000))
		{
			::printf("Init 127.0.0.1:6000 failed with code: %d", s.code);
			break;
		}

		while (TRUE)
		{
			::printf("等接连接...\n");
			if (s.HasConnect())
			{
				char remote[32];
				::memset(remote, 0, sizeof(remote));
				s.GetRemoteAddr(remote);
				::printf("remote host: %s connect\n", remote);

				while (TRUE)
				{
					if (xuwn::CSocket::FdCanRead(s.GetSocket()))
					{
						// 自定义为接收8个字符,测试用
						char buf[32];
						::memset(buf, 0, sizeof(buf));
						int rc = ::recv(s.GetSocket(), buf, 8, 0);

						if (rc == 8)
							::printf("recv buf: %s\n", buf);
					}
				}
			}
			else
			{
				Sleep(1000);
			}
		}
	}
	printf("Hello World!\n");
	return 0;
}

⌨️ 快捷键说明

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