Ejemplo de aplicación servidor
#include <fstream>
{
pthread_mutex_lock(t_arg->
mutex);
cout <<
"Worker " << t_arg->
id <<
": connection terminated" << endl;
pthread_mutex_unlock(t_arg->
mutex);
{
}
if(t_arg != 0)
{
delete t_arg;
t_arg = 0;
}
pthread_exit(NULL);
}
{
while(true)
{
string message;
cout <<
"Worker " << t_arg->
id <<
" received: " << message << endl;
string send = "You said: ";
send += message;
}
}
{
}
{
for(int i = 0; i < str->length(); i++)
{
if((*str)[i] == 32 || (*str)[i] == 10 || (*str)[i] == 11)
{
str->erase(i--,1);
}
}
}
{
*ip = "";
*port = 0;
ifstream confFile;
if(!confFile.is_open())
{
cout << "Error opening configuration file" << endl;
return false;
}
string parameter;
while(true)
{
getline(confFile, parameter, '=');
if(confFile.eof())
{
break;
}
if(parameter == "bind-ip")
{
confFile >> *ip;
}
else if(parameter == "port")
{
confFile >> *port;
}
}
confFile.close();
if(*ip == "" || *port == 0)
{
return false;
}
return true;
}
{
string ip;
int port;
{
cout << "Configuration couldn't be loaded" << endl;
return -1;
}
return 0;
}