It is Connection Refused ACE application in Android

I put the ACE source code is ported to the Android, through the JNI method calls, mobile phone as a Client, Linux as the server, a simple message interaction Demo, oddly enough, the same code, between PC and PC is no problem, but in the Android and PC have been reported errno=111 Connection Refused

To put the client end of the code on the Android:
    int ACE_Agent::init(const char *strPort , const char *strHost)
{
if ( !strPort || !strHost )
{
return -1;
}
mConnector = new ACE_SOCK_Connector();

mAddr.set(strPort , strHost);
ACE_Time_Value timeout(5);

int result = mConnector->connect(mStream , mAddr , &timeout);
if( 0 != result )
{
LOGE("*ERROR* Fail to Connect the Server ! result = %d errno = %d , strerr = %s 10s\n",result,errno,strerror(errno));
return -1;
}

IsInit = true;

LOGI("ACE Init Success !\n");

//show_internet_address();

return 0;
}


The server server code:
    void *pthread_function_one(void *pArg)
{
int result = 0 , width = 0;
ACE_Handle_Set active_handle_set;

std::map<std::string , ACE_SOCK_Stream>::iterator iter;

struct timeval tv = {1, 0};
ACE_Time_Value atv(tv);

printf("max_set = %d\n",(int)handle_set.max_set());

while ( 1 )
{
active_handle_set = handle_set;
width = (int)active_handle_set.max_set() + 1; //max_set() Returns the number of the large bit. UNIX +1 descriptor

if (ACE::select(width , &active_handle_set , 0 , 0 , &atv) <1) //ACE:: returns the number of the handle of the select activity
{
continue;
}

/*
for(int i = 0; i <active_handle_set.num_set() ; i++)
{
printf("handle = %d , num_set = %d\n",i ,active_handle_set.num_set());
}
*/

int set_size = active_handle_set.num_set();
if (set_size > 0)
{
std::cout<<"set_size = "<<set_size<<std::endl;
}


#if 0 //ACE_Handle_Set polling ordinary
for (iter = STRING_STREAM.begin() ; iter != STRING_STREAM.end() ; iter++)
{
if (active_handle_set.is_set((iter->second).get_handle()))
{
ACE_INET_Addr inet_addr;
(iter->second).get_remote_addr(inet_addr);
std::cout<<"<==== The Data from "<<inet_addr.get_host_addr()<<" ====>"<<std::endl;
handle_data(iter->second);
active_handle_set.clr_bit(iter->second.get_handle());
}
}
#endif


ACE_Handle_Set_Iterator iterator(active_handle_set);
//ACE_Handle_Set_Iterator iteration
ACE_SOCK_Stream tmp;

ACE_HANDLE handle = iterator();

for ( ;handle != ACE_INVALID_HANDLE; handle = iterator())
{
//
ACE_INET_Addr inet_addr;
tmp.set_handle(handle);
tmp.get_remote_addr(inet_addr);
std::cout<<"<==== The Data from "<<inet_addr.get_host_addr()<<" ====>"<<std::endl;
handle_data(tmp);
}


}
}

Started by Brady at December 01, 2016 - 6:24 AM

Top! Ding Ding Ding

Posted by Brady at December 03, 2016 - 6:32 AM