superdog/server/swarm.cpp

65 lines
1.4 KiB
C++
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

/*
* @Author: your name
* @Date: 2021-06-30 10:02:04
* @LastEditTime: 2021-08-29 00:56:54
* @LastEditors: Please set LastEditors
* @Description: In User Settings Edit
* @FilePath: \server\main.cpp
*/
#define _WSPIAPI_H_
#define _WINSOCKAPI_
#include <iostream>
#include "tcp_swarm_libevent.h"
#ifdef WIN32
#include "winsock2.h"
#endif
#include <stdio.h>
#include <thread>
#include <stdlib.h>
#ifdef linux
#include <unistd.h>
#endif
using namespace std;
int main(){
#ifdef WIN32
WORD wdVersion = MAKEWORD(2, 2);//定义自己需要的网络库版本这里是2.2
WSADATA wdSockMsg;//这是一个结构体
int nRes = WSAStartup(wdVersion, &wdSockMsg);//打开一个套接字
if (0 != nRes) {
switch (nRes) {
case WSASYSNOTREADY:
printf("check your library");
break;
case WSAVERNOTSUPPORTED:
printf("need updated");
break;
case WSAEINPROGRESS:
printf("need reboot");
break;
case WSAEPROCLIM:
printf("sdfsdfsa");
break;
}
}
if (2 != HIBYTE(wdSockMsg.wVersion) || 2 != LOBYTE(wdSockMsg.wVersion)) {
printf("WSACleanup");
WSACleanup();
return 0;
}
#endif
std::cout<<"start swarm client libevent\r\n";
TcpSwarmClientLibevent swarm(20);
swarm.ConnectToServer("127.0.0.1", 8000);
while(true){
#ifdef WIN32
Sleep(1000);
#endif
#ifdef linux
usleep(1000);
#endif
}
}