acl/lib_acl_cpp/samples/socket/server/main.cpp
2014-11-19 00:25:21 +08:00

43 lines
745 B
C++

#include "acl_cpp/lib_acl.hpp"
#include <stdlib.h>
#include <stdio.h>
int main(int argc, char* argv[])
{
acl::server_socket server;
acl::string addr = "127.0.0.1:9001";
if (argc >= 2)
addr = argv[1];
if (server.open(addr) == false)
{
printf("open %s error\r\n", addr.c_str());
return 1;
}
else
printf("open %s ok\r\n", addr.c_str());
while (true)
{
acl::socket_stream* client = server.accept();
if (client == NULL)
{
printf("accept failed: %s\r\n", acl::last_serror());
break;
}
if (client->write("hello world\r\n") == false)
{
printf("write error\r\n");
delete client;
continue;
}
delete client;
printf("close client ok\r\n");
}
return (0);
}