#define SIZE_DATA 18
#define SIZE_BUF 1024
#define NO_ITERATIONS 5
//#define ACE_HAS_TOKENS_LIBRARY
class Server
{
public:
Server (int port): server_addr_(port),peer_acceptor_(server_addr_)
{
data_buf_= new char[SIZE_BUF];
}
//Handle the connection once it has been established. Here the
//connection is handled by reading SIZE_DATA amount of data from the
//remote and then closing the connection stream down.
int handle_connection()
{
// Read data from client
for(int i=0;i<NO_ITERATIONS;i++)
{
int byte_count=0;
if( (byte_count=new_stream_.recv_n (data_buf_, SIZE_DATA, 0))==-1)
ACE_ERROR ((LM_ERROR, "%p\n", "Error in recv"));
else
{
data_buf_[byte_count]=0;
ACE_DEBUG((LM_DEBUG,"Server received %s \n",data_buf_));
}
}
// Close new endpoint
if (new_stream_.close () == -1)
ACE_ERROR ((LM_ERROR, "%p\n", "close"));
return 0;
}
//Use the acceptor component peer_acceptor_ to accept the connection
//into the underlying stream new_stream_. After the connection has been
//established call the handle_connection() method.
int accept_connections ()
{
if (peer_acceptor_.get_local_addr (server_addr_) == -1)
ACE_ERROR_RETURN ((LM_ERROR,"%p\n","Error in get_local_addr"),1);
ACE_DEBUG ((LM_DEBUG,"Starting server at port %d\n",
server_addr_.get_port_number ()));
// Performs the iterative server activities.
while(1)
{
ACE_Time_Value timeout (ACE_DEFAULT_TIMEOUT);
if (peer_acceptor_.accept (new_stream_, &client_addr_, &timeout)== -1)
{
ACE_ERROR ((LM_ERROR, "%p\n", "accept"));
continue;
}
else
{
ACE_DEBUG((LM_DEBUG,
"Connection established with remote %s:%d\n",
client_addr_.get_host_name(),client_addr_.get_port_number()));
//Handle the connection
handle_connection();
}
}
}
private:
char *data_buf_;
ACE_INET_Addr server_addr_;
ACE_INET_Addr client_addr_;
ACE_SOCK_Acceptor peer_acceptor_;
ACE_SOCK_Stream new_stream_;
};
int main (int argc, char *argv[])
{
if(argc<2)
{
ACE_ERROR((LM_ERROR,"Usage %s <port_num>", argv[0]));
ACE_OS::exit(1);
}
Server server(ACE_OS::atoi(argv[1]));
server.accept_connections();
return 0;
}
文件肯定没问题
vc 2003 可以编译 运行正常
linux 下 我
1. 在/usr/local目录下解压缩:
tar -xzvf ACE-5.3+TAO-1.3.tar.gz
2.cd ACE_wrappers
find -name \*dsp -o -name \*dsw -o -name \*bor|xargs rm -f
3.export ACE_ROOT="/usr/local/ACE_wrappers"
4.cd $ACE_ROOT/ace
ln -s config-linux.h config.h
5.cd $ACE_ROOT/include/makeinclude
ln -s platform_linux.GNU platform_macros.GNU
6.export LD_LIBRARY_PATH=$ACE_ROOT/ace:$ACE_ROOT/lib:$LD_LIBRARY_PATH
7.cd $ACE_ROOT
make
基本上是这么做的
$ACE_ROOT/ace 下面有lib文件了
/home/aaa/ACE_wrappers/ace/libACE.so
/home/aaa/ACE_wrappers/ace/libACE.so.5.5.0
编译命令
g++ test.cpp -I$ACE_ROOT -L$ACE_ROOT
错误
如果 使用g++ test.cpp -I$ACE_ROOT -L$ACE_ROOT -c 是可以的
所以应该是连接上面的错
铁错误的代码
test.cpp:92:2: warning: no newline at end of file
/tmp/ccVkVPDD.o(.text+0x24): In function `main':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.text+0x2c): In function `main':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.text+0x46): In function `main':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.text+0x60): In function `main':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.text+0x6d): In function `main':
: undefined reference to `ACE_OS::exit(int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerD1Ev+0x36): In function
`Server::~Server()':
: undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerD1Ev+0x50): In function
`Server::~Server()':
: undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerD1Ev+0x70): In function
`Server::~Server()':
: undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x18):
In function `Server::accept_connections()':
: undefined reference to `ACE_SOCK::get_local_addr(ACE_Addr&) const'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x25):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x2d):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x47):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x61):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x75):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x7d):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x97):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0xbf):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0xfa):
In function `Server::accept_connections()':
: undefined reference to `ACE_SOCK_Acceptor::accept(ACE_SOCK_Stream&,
ACE_Addr*, ACE_Time_Value*, int, int) const'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x107):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x10f):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x129):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x143):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x150):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x158):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x172):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x19a):
In function `Server::accept_connections()':
: undefined reference to `ACE_INET_Addr::get_host_name() const'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server18accept_connectionsEv+0x1ad):
In function `Server::accept_connections()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x47):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x4f):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x69):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x83):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x98):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0xa0):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0xba):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0xd1):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0xed):
In function `Server::handle_connection()':
: undefined reference to `ACE_SOCK_Stream::close()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0xfa):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::last_error_adapter()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x102):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::instance()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x11c):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::conditional_set(char const*,
int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6Server17handle_connectionEv+0x136):
In function `Server::handle_connection()':
: undefined reference to `ACE_Log_Msg::log(ACE_Log_Priority, char
const*, ...)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN3ACE6recv_nEiPvjiPK14ACE_Time_ValuePj+0x1f):
In function `ACE::recv_n(int, void*, unsigned int, int, ACE_Time_Value
const*, unsigned int*)':
: undefined reference to `ACE::recv_n_i(int, void*, unsigned int, int,
unsigned int*)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN3ACE6recv_nEiPvjiPK14ACE_Time_ValuePj+0x41):
In function `ACE::recv_n(int, void*, unsigned int, int, ACE_Time_Value
const*, unsigned int*)':
: undefined reference to `ACE::recv_n_i(int, void*, unsigned int, int,
ACE_Time_Value const*, unsigned int*)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN14ACE_Time_Value3setEll+0x1e): In
function `ACE_Time_Value::set(long, long)':
: undefined reference to `ACE_Time_Value::normalize()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerC1Ei+0x1b): In function
`Server::Server(int)':
: undefined reference to `ACE_INET_Addr::ACE_INET_Addr(unsigned short,
unsigned int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerC1Ei+0x2d): In function
`Server::Server(int)':
: undefined reference to `ACE_INET_Addr::ACE_INET_Addr()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerC1Ei+0x4e): In function
`Server::Server(int)':
: undefined reference to `ACE_SOCK_Acceptor::ACE_SOCK_Acceptor(ACE_Addr
const&, int, int, int, int)'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerC1Ei+0xcf): In function
`Server::Server(int)':
: undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN6ServerC1Ei+0xec): In function
`Server::Server(int)':
: undefined reference to `ACE_INET_Addr::~ACE_INET_Addr()'
/tmp/ccVkVPDD.o(.gnu.linkonce.t._ZN11ACE_SOCK_IOC2Ev+0xd): In function
`ACE_SOCK_IO::ACE_SOCK_IO()':
: undefined reference to `ACE_SOCK::ACE_SOCK()'
collect2: ld returned 1 exit status
解决具体的问题先
你们是在linux 下面用吗?
你们怎么安装的?
--
☆==☆☆==☆☆==☆☆==☆☆==☆☆==☆
NEC Solutions(China)Co.,Ltd.
ソフトウェア開発事業部
大連第一開発部
胡 毅(コ キ)
♪連絡先
◇ TEL (86)0411-84754455-232
◇ e-Mail huy...@gmail.com
◇ GTalk huy...@gmail.com
◇ BLOG www.cppblog.com/huyi
☆==☆☆==☆☆==☆☆==☆☆==☆☆==☆
怎么按部就班的
运行那个sh 文件吗?
在 06-4-13,papamms<ppms...@gmail.com> 写道:
会错误的
说没有
问题 终于解决了
我用的是 -lace
应该是 -lACE