Ejemplo n.º 1
0
	void EntryBase::UpdateEntityTime ()
	{
		const auto& now = QDateTime::currentDateTime ();
		if (LastEntityTimeRequest_.isValid () &&
				LastEntityTimeRequest_.secsTo (now) < 60)
			return;

		connect (Account_->GetClientConnection ()->GetEntityTimeManager (),
				SIGNAL (timeReceived (QXmppEntityTimeIq)),
				this,
				SLOT (handleTimeReceived (QXmppEntityTimeIq)),
				Qt::UniqueConnection);

		LastEntityTimeRequest_ = now;

		auto jid = GetJID ();

		auto timeMgr = Account_->GetClientConnection ()->GetEntityTimeManager ();
		if (jid.contains ('/'))
		{
			timeMgr->requestTime (jid);
			return;
		}

		for (const auto& variant : Variants ())
			if (!variant.isEmpty ())
				timeMgr->requestTime (jid + '/' + variant);
	}
Ejemplo n.º 2
0
ChatClient::ChatClient(QObject *parent)
    : QXmppClient(parent)
    , d(new ChatClientPrivate)
{
    bool check;
    Q_UNUSED(check);

    check = connect(this, SIGNAL(connected()),
                    this, SLOT(_q_connected()));
    Q_ASSERT(check);

    check = connect(this, SIGNAL(error(QXmppClient::Error)),
            this, SLOT(_q_error(QXmppClient::Error)));
    Q_ASSERT(check);

    check = connect(this, SIGNAL(messageReceived(QXmppMessage)),
            this, SLOT(_q_messageReceived(QXmppMessage)));
    Q_ASSERT(check);

    // DNS lookups
    check = connect(&d->dns, SIGNAL(finished()),
                    this, SLOT(_q_dnsLookupFinished()));
    Q_ASSERT(check);

    // service discovery
    d->discoManager = findExtension<QXmppDiscoveryManager>();
    check = connect(d->discoManager, SIGNAL(infoReceived(QXmppDiscoveryIq)),
                    this, SLOT(_q_discoveryInfoReceived(QXmppDiscoveryIq)));
    Q_ASSERT(check);

    check = connect(d->discoManager, SIGNAL(itemsReceived(QXmppDiscoveryIq)),
                    this, SLOT(_q_discoveryItemsReceived(QXmppDiscoveryIq)));
    Q_ASSERT(check);

    // server time
    d->timeManager = findExtension<QXmppEntityTimeManager>();
    check = connect(d->timeManager, SIGNAL(timeReceived(QXmppEntityTimeIq)),
                    this, SLOT(_q_timeReceived(QXmppEntityTimeIq)));
    Q_ASSERT(check);

    // file transfers
    transferManager()->setSupportedMethods(QXmppTransferJob::SocksMethod);

    // multimedia calls
    callManager();

    // diagnostics
    diagnosticManager();

    qDebug("ChatClient 0x%llx created", reinterpret_cast<qint64>(this));
    chatClients.append(this);
    theClientObserver()->clientCreated(this);
}
Ejemplo n.º 3
0
CString CMt5Client::RequestKDataThread(LPVOID pParam)
{
	struct aa
	{
		CString port;
		CString ip;
		CString symbol;
		EnumReqHistoryDataType ktype;
	} mtBroker;
	mtBroker.port = CString("5050");
	mtBroker.ip = CString("192.168.0.212");
	mtBroker.symbol = CString("XAUUSD");
	mtBroker.ktype = HistoryPeriodD1;

	//mid 以下为TcpClient变量(本程序客户端,用于连接Mt5TcpServer)
	BOOL	bIsConnected = TRUE;
	BOOL	bReturn = FALSE;
	int		iTimesAlreadyConnected = 0;	//mid 已连接次数
	const	int	iTimesToConnect = 1;	//mid 尝试连接次数,超过次数之后,不在连接,并标注连接失败

	SOCKET			socketRequest;
	sockaddr_in		socketClientAddr;		//mid 远端Mt5TcpServerSocket地址

	//mid 1)设置将要连接的服务器地址
	//mid 獲取Port
	int iPort = _ttol(mtBroker.port);
	//mid 獲取Ip
	char szIp[30];
	memset(szIp, 0, sizeof(szIp));
	wcstombs(szIp, mtBroker.ip, mtBroker.ip.GetLength() * 2);
	//unsigned long lIp = ntohl(inet_addr(szIp));



	socketClientAddr.sin_addr.s_addr = inet_addr(szIp);
	socketClientAddr.sin_family = AF_INET;
	socketClientAddr.sin_port = htons(iPort); //5000;		
	//mid 2)创建socket
	socketRequest = socket(AF_INET, SOCK_STREAM, 0);

	/*mid
	此两方法成对出现,一个使有效,一个使无效
	CreateSocketClient("192.168.1.212", 5000);
	closesocket(m_SocketClient);
	*/
	while (connect(socketRequest, (sockaddr*)&(socketClientAddr), sizeof(socketClientAddr)))
	{//连接到服务器
		DWORD dwErr;
		dwErr = GetLastError();
		if (10056 == dwErr)
		{	//mid 在一个已连接的套接字上面进行连接,说明在Connect()函数中已有connect()成功
			bIsConnected = TRUE;
			break;
		}

		if (iTimesAlreadyConnected>iTimesToConnect)
		{	//mid 尝试连接
			bIsConnected = FALSE;
			AfxMessageBox(TEXT("Connect() Connect Error."));
			break;
		}
		iTimesAlreadyConnected++;
	}
	if (bIsConnected)
	{
		TRACE("\n连接成功\n");
		REQ_HEADER reqHeader;
		reqHeader.ReqType = ReqTypeHistory;
		if (send(socketRequest, (char*)&reqHeader, sizeof(REQ_HEADER), 0) == sizeof(REQ_HEADER))
		{
			TRACE("\n请求类型数据头发送成功\n");
			REQ_HISTORY reqHistory;
			memset(&reqHistory, 0, sizeof(REQ_HISTORY));
			//mid 1)将UNICODE字串转化为utf8
			char * szSymbol = UnicodeToUTF_8First(mtBroker.symbol);
			strncpy(reqHistory.symbol, szSymbol, min(sizeof(reqHistory.symbol) / 2/*mid 只能假設每個字符佔用2個字節,防止溢出*/, mtBroker.symbol.GetLength()));
			//mid 2)释放转换结果
			delete[] szSymbol;
			//strncpy(reqHistory.symbol, "XAUUSD", min(sizeof(reqHistory.symbol) / 2/*mid 只能假設每個字符佔用2個字節,防止溢出*/, mtBroker.symbol.GetLength()));
			reqHistory.type = mtBroker.ktype;
			int iSizeOfReqHistory = sizeof(REQ_HISTORY);
			if (send(socketRequest, (char*)&reqHistory, sizeof(REQ_HISTORY), 0) == sizeof(REQ_HISTORY))
			{
				TRACE("\n历史数据请求发送成功\n");
				RSP_HISTORY_HEADER rspHistoryHeader;
				memset(&rspHistoryHeader, 0, sizeof(RSP_HISTORY_HEADER));
				if (recv(socketRequest, (char*)&rspHistoryHeader, sizeof(RSP_HISTORY_HEADER), 0) == sizeof(RSP_HISTORY_HEADER))
				{
					TRACE("\n历史数据数据头接收成功\n");
					EnumReqHistoryDataType	rspKType = rspHistoryHeader.m_type;
					CString					strRspSymbol = Utf_8ToUnicode(rspHistoryHeader.m_szSymbol);
					int						nRspCount = rspHistoryHeader.m_nCount;
					if (rspKType == mtBroker.ktype && mtBroker.symbol.CompareNoCase(strRspSymbol) == 0)
					{
						RSP_HISTORY *pHistoryArray = new RSP_HISTORY[nRspCount];		//mid 据answer描述的数据大小定义数组大小,需要手动删除掉
						int const nTotalBytesToReceive = nRspCount*sizeof(RSP_HISTORY);		//mid 待接收数据总量,
						memset(pHistoryArray, 0, nTotalBytesToReceive);

						if (RecvAll(socketRequest, pHistoryArray, nTotalBytesToReceive))
						{
							TRACE("\n历史数据接收成功\n");
							CString KData;
							for (int i = 0; i < nRspCount; i++)											//mid 按 [0,9] 共10个数循环	获得MT 发来数据。
							{																							//mid 装载	下标:[1,10],剩余下标[11],有何深意??,无用,已去除。
								//mid 1)获得code
								//strncpy(pKData[i].m_szCode, strRspSymbol, min(sizeof(pKData[i].m_szCode), strRspSymbol.GetLength()));
								//mid 2)获得时间
								MqlDateTime MqlTime = pHistoryArray[i].m_time;
								CTime timeReceived(MqlTime.year, MqlTime.mon, MqlTime.day, MqlTime.hour, MqlTime.min, MqlTime.sec);
								CString timeStr = timeReceived.Format("\n%Y年%m月%d日%H时%M分%S秒\n");
								//TRACE(timeStr);
								//pKDATA[i].m_qwTime = ToStockTime(&timeReceived);
								//mid 3)获得数值数据
								int m_dOpen = pHistoryArray[i].m_fOpen;	//mid 开始 OHLCVA数据,原先是要*0.001,是因数据在网上发送时使用整数(*1000),在此还原
								int m_dHigh = pHistoryArray[i].m_fHigh;	//mid MT数据暂时没有如此处理,所以不用转换。
								int m_dLow = pHistoryArray[i].m_fLow;
								int m_dClose = pHistoryArray[i].m_fClose;
								int m_llVolume = pHistoryArray[i].m_fVolume;
								int m_dAmount = pHistoryArray[i].m_fAmount;



								CString str;
								str.Format(CString("%s,%d,%d,%d,%d,%d,%d\r\n"), timeStr, m_dOpen, m_dHigh, m_dLow, m_dClose, m_llVolume, m_dAmount);
								KData = KData + str;


							}
							delete[] pHistoryArray;

							return KData;
							//---02
							//mid 以上数据准备完毕,以下准备发送
							//UINT nMsgType = CStock::dataK;//mid 發送的數據的類型
							//::SendMessage(pMt5->m_hExchangerWnd, pMt5->m_uiNewDataMsg, nMsgType, (LPARAM)(pKData));
						}
						else
						{
							TRACE("\n历史数据接收失败\n");
						}
						//mid 无条件释放数据接收缓存
						delete[] pHistoryArray;
					}
					else
					{
						AfxMessageBox(TEXT("Responded Error History Data KType."));
					}
				}
				else
				{
					DWORD dwErr;
					dwErr = GetLastError();
					TRACE(TEXT("\n历史数据数据头接收失败\n"));
				}
			}
			else
			{
				DWORD dwErr;
				dwErr = GetLastError();
				TRACE(TEXT("\n历史数据请求发送失败\n"));
			}
		}
		else
		{
			DWORD dwErr;
			dwErr = GetLastError();
			TRACE("\n请求类型数据头发送失败\n");
		}
	}
	else
	{
		DWORD dwErr;
		dwErr = GetLastError();
		CString str;
		str.Format(TEXT("\n连接失败,ErrorNo:%d\n"), dwErr);
		TRACE(str);
	}
	closesocket(socketRequest);
	AfxEndThread(0);
	return 0;
}
Ejemplo n.º 4
0
void Reverb::midiTimeReceived(unsigned short rawVal)
{
  emit timeReceived(raw2Phys(rawVal, 10.0, 0.0));
}