socket随写

            //Socket客户端开启
            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;
}
//---------------------------------------------------------------------------

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值