superdog/server/main.cpp

57 lines
1.3 KiB
C++
Raw Normal View History

2021-07-02 05:53:07 +00:00
/*
* @Author: your name
* @Date: 2021-06-30 10:02:04
2023-03-12 16:37:25 +00:00
* @LastEditTime: 2022-03-23 20:24:19
2021-07-02 09:25:47 +00:00
* @LastEditors: Please set LastEditors
2021-07-02 05:53:07 +00:00
* @Description: In User Settings Edit
* @FilePath: \server\main.cpp
*/
2021-07-06 15:30:40 +00:00
#define _WSPIAPI_H_
#define _WINSOCKAPI_
2021-06-24 07:09:25 +00:00
#include <iostream>
2021-06-30 09:31:56 +00:00
#include "tcp_server_libevent.h"
2021-07-05 14:49:02 +00:00
#ifdef WIN32
#include <winsock2.h>
#endif
2021-06-30 09:31:56 +00:00
#include <stdio.h>
2021-07-02 09:25:47 +00:00
#include <thread>
#include <stdlib.h>
2021-06-30 09:31:56 +00:00
2021-07-02 09:25:47 +00:00
using namespace std;
2021-06-24 07:09:25 +00:00
int main(){
#ifdef WIN32
2021-06-30 09:31:56 +00:00
WORD wdVersion = MAKEWORD(2, 2);//定义自己需要的网络库版本这里是2.2
WSADATA wdSockMsg;//这是一个结构体
int nRes = WSAStartup(wdVersion, &wdSockMsg);//打开一个套接字
2021-07-02 05:53:07 +00:00
if (0 != nRes) {
switch (nRes) {
2021-06-30 09:31:56 +00:00
case WSASYSNOTREADY:
printf("check your library");
break;
case WSAVERNOTSUPPORTED:
printf("need updated");
break;
case WSAEINPROGRESS:
printf("need reboot");
break;
case WSAEPROCLIM:
printf("sdfsdfsa");
break;
}
}
2021-07-02 05:53:07 +00:00
if (2 != HIBYTE(wdSockMsg.wVersion) || 2 != LOBYTE(wdSockMsg.wVersion)) {
printf("WSACleanup");
2021-06-30 09:31:56 +00:00
WSACleanup();
return 0;
}
#endif
2021-07-05 03:20:04 +00:00
std::cout<<"start server\r\n";
2021-07-02 09:25:47 +00:00
TcpServerLibevent server(8000,"0.0.0.0");
server.StartServerSync();
while(true){
#ifdef WIN32
2021-07-04 17:05:27 +00:00
Sleep(1000);
#endif
2021-07-02 09:25:47 +00:00
}
}