clntsckt->Address = "127.0.0.1";
clntsckt->Port = 23456;
clntsckt->Open();
//---------------------------------------------------------------------------
bool TMasterMain::ConnectRMDSServer()
{
//建立Socket连接
struct sockaddr_in server;
struct hostent *host = NULL;
socketRMDSClient = socket(AF_INET, SOCK_STREAM, IPPROTO_TCP);
if (socketRMDSClient == INVALID_SOCKET)
{
AddXNetLog(lang::TBackLog::logError,"创接连接RMDS套接字接口失败...");
return false;
}
server.sin_family = AF_INET;
server.sin_port = htons(RMDSPort);
server.sin_addr.s_addr = inet_addr(RMDSAddress);
if (server.sin_addr.s_addr == INADDR_NONE)
{
host = gethostbyname(RMDSAddress);
if (host == NULL)
{
AddXNetLog(lang::TBackLog::logError,"转换RMDS接口IP地址失败");
return false;
}
CopyMemory(&server.sin_addr, host->h_addr_list[0],host->h_length);
}
if (connect(socketRMDSClient, (struct sockaddr *)&server, sizeof(server)) == SOCKET_ERROR)
{
AddXNetLog(lang::TBackLog::logError,"连接RMDS服务器失败");
return false;
}
return true;
}
//---------------------------------------------------------------------------
void *TMasterMain::CreateCheckThread (void *Owner)
{
TMasterMain *thread = (TMasterMain *)Owner;
thread->CheckOnLineThread();
return NULL;
}
//---------------------------------------------------------------------------
int TMasterMain::CheckOnLineThread()
{
while(1)
{
if (!bRMDSConnected)
{
AddXNetLog(lang::TBackLog::logError,"尝试连接RMDS服务器...");
//连接Socket服务器
bRMDSConnected = ConnectRMDSServer();
if (bRMDSConnected)
AddXNetLog(lang::TBackLog::logError,"连接RMDS服务器成功");
}
Sleep(RMDSInterval);
}
return 0;
}
//---------------------------------------------------------------------------
bool TMasterMain::SendRMDSData (char* contenct, int lengh)
{
bool flag = false;
int ret = send(socketRMDSClient, contenct, lengh, 0);
if (ret == SOCKET_ERROR)
{
AddXNetLog(lang::TBackLog::logError,"向RMDS发送数据失败");
bRMDSConnected = false;
}
else
{
AddXNetLog(lang::TBackLog::logError,"向RMDS发送数据成功");
Logger->AddLog(lang::TBackLog::logDebug, "向RMDS发送数据成功 发送长度=%d\n", ret);
flag = true;
}
return flag;
}
//---------------------------------------------------------------------------