⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 dogclient.cpp

📁 电信的97接口程序,用于把话单入库。这里是采用FTP方式采集话单
💻 CPP
字号:
/*+============================================================================
File:       DogClient.cpp
Summary:    Watch dog client timer class.
History:
2000/07/12	V1.0
	Start it by shencan@263.net
2000/07/19	V1.1
	Use UDP to transport message. (shencan@263.net)
2001/01/07	V1.2
	Check database config and update config. (shencan@263.net)
2002/04/27	
	Convert librery with PWLIB
============================================================================+*/
#include "dogclient.h"

#define MIN(x,y) ((x) < (y) ? (x) : (y))

int CDogClient::id = 1;
CDogClient * CDogClient::m_instance = NULL;

CDogClient::CDogClient()
{
	m_sock = 0;
	m_instance = this;
}

CDogClient::~CDogClient()
{
}

int CDogClient::Init()
{
	// alloc the mem for sock
	struct hostent * hp;

	m_sock = socket(AF_INET, SOCK_DGRAM, 0);

	if(m_sock < 0)
		return -1;
	
	m_srv.sin_family = AF_INET;
	
	hp = gethostbyname(DEFAULT_SERVER);
	if(hp == 0)
		return -2;

	memcpy((char *)&m_srv.sin_addr, (char *)hp->h_addr, hp->h_length);
//	m_srv.sin_port = htons(DEFAULT_PORT);
	m_srv.sin_port = htons(CGlobal::Instance()->m_port);

	return 0;
}

int CDogClient::SendMsg(MessageCode code, char * msg)
{
	size_t len;
	int i;

	CWatchMessage lp;

	lp.m_msgCode = code;
	lp.m_id = id++;

	i = MIN(MESSAGE_LEN, strlen(msg));
	memcpy(lp.m_msg, msg, i);
	lp.m_msg[i] = 0;

	len = sizeof(CWatchMessage);

//	if(m_sock->Write((char *)&lp, len) == FALSE)
//		return -1;

	if(sendto(m_sock, (char *)&lp, len, 0,
		(struct sockaddr *)&m_srv, sizeof(m_srv)) < 0)
		return -1;

	return 0;
}

int CDogClient::Close()
{
	closesocket(m_sock);
	return 0;
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -