#include "PreHeader.h"
#include "base64.h"
#include "ServerManager.h"
#include "WebFrameData.h"
#pragma comment(lib, "wininet.lib")//winsock
#pragma comment(lib,"Ws2_32.lib")//winsock
int main(){
const char* host="127.0.0.1";
const char* port="38950";
SOCKET mServerSocket;
ServerManager* mServerManger=new ServerManager();
mServerManger->start_server(host,port); //启动服务器,并且start_server()是对齐监听,接收,解析,发送信息
while (true)
{
//首先获取连接,返回连接的SOCK
SOCKET clientSocket=mServerManger->accept_client();
mServerManger->StartThread(clientSocket);
}
mServerManger->close_server(); //关闭服务器
delete mServerManger;
return 0;
}
#include "ace/SOCK_Acceptor.h"
#include "ace/SOCK_Stream.h"
#include "ace/INET_Addr.h"
#include "ace/Auto_Ptr.h"
#include "ace/Mem_Map.h"
#include "stdio.h"
#include <iostream>
using namespace std;
#define SIZE_DATA 18
#define SIZE_BUF 1024
#define NO_ITERATIONS 5
int main(int argc,char* argv[]){
ACE_SOCK_Acceptor peer_acceptor_;
ACE_SOCK_Stream peer_stream_;
ACE_INET_Addr addr_server_;
//设置addr_server_的host,port,即主服务器的端口号,host
addr_server_.set("20020","localhost");
peer_acceptor_.open(addr_server_);//open方法调用底层socket(),bind(),listen()函数
std::cout<<"Server start!"<<endl;
while(true)
{
if(peer_acceptor_.accept(peer_stream_)==-1) return 1; //进行连接
peer_stream_.disable(ACE_NONBLOCK);// ensure blocking <send_n>
char bb[10];
peer_stream_.recv_n(bb,7); //接收数据
std::cout<<bb<<endl;
if(peer_stream_.send_n("hello",6)==-1) return 1;
peer_stream_.close();
}
return 0;
}; |