为什么glox不起作用
Why gloox does not work?
我正在尝试使用C++glox库,首先我尝试从这里运行示例
https://github.com/knatten/blog.knatten.org/blob/master/gloox/bot.cpp
然后我尝试了另一个给定的例子,但我甚至看不到我的客户是在线的。。。如何发送至少发送状态信息并联机?我的电脑有问题吗?我在用Ubuntu。
#include <gloox/client.h>
#include <gloox/messagehandler.h>
#include <gloox/message.h>
#include <gloox/presencehandler.h>
#include <gloox/connectionlistener.h>
#include <iostream>
#include <string>
using namespace std;
using namespace gloox;
//my one
const string LOGIN = "gmail.com";
ostream& operator<<(ostream& os, Message::MessageType type) {
switch (type) {
case Message::Chat:
os << "Chat";
break;
case Message::Error:
os << "Error";
break;
case Message::Groupchat:
os << "Groupchat";
break;
case Message::Headline:
os << "Headline";
break;
case Message::Normal:
os << "Normal";
break;
case Message::Invalid:
os << "Invalid";
break;
default:
os << "unknown type";
break;
}
return os;
}
ostream& operator<<(ostream& os, const Message& stanza) {
os << "type:'" << stanza.subtype() << "' from:'" << stanza.from().full() << "' body:'" << stanza.body() << "'";
return os;
}
class Bot : public MessageHandler,
/*public PresenceHandler,*/
public ConnectionListener
/*,public RosterListener*/{
public:
Bot(){
JID jid( "mmaaria123@gmail.com/home" );
client = new Client( jid, "mmaaria123" );
client->registerConnectionListener( this );
client->registerMessageHandler( this );
client->connect(true);
}
virtual void onConnect() {
cout << "It is connected good:)" << endl;
sleep(5);
client->disconnect();
}
virtual void onDisconnect(ConnectionError e) {
cout << "ConnListener::onDisconnect() " << endl;
}
virtual bool onTLSConnect(const CertInfo& Info) {
time_t tm = Info.date_from;
time_t tm_to = Info.date_to;
cout << "t Certificate information to " << LOGIN << endl;
cout << "t========================================" << endl;
// number code << "tServer status: " << Info.status;
if (Info.status !=0)
{
cout << "t !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
cout << "t !!! The certificate has a problem !!!" << endl;
cout << "t !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!" << endl;
// parsing binary Status Cert
if ((CertInvalid) & Info.status)
{
cout << "t- The certificate is not trusted " << endl;
}
if (( CertSignerUnknown) & Info.status)
{
cout << "t- The certificate hasn't got a kown issuer" << endl;
}
if ((CertRevoked) & Info.status)
{
cout << "t- The certificate has been revoked " << endl;
}
if ((CertExpired) & Info.status)
{
cout << "t- The certificate has expired " << endl;
}
if ((CertNotActive) & Info.status)
{
cout << "t- The certificate is not yet active " << endl;
}
if ((CertWrongPeer) & Info.status)
{
cout << "t- The certificate has not issued for the peer we're connected to " << endl;
}
if ((CertSignerNotCa) & Info.status)
{
cout << "t- The signer is not CA " << endl;
}
cout << endl;
}
// end parsing
else
// if Info.status=0 sertificate is valide
cout << " *** Cert is OK!" << endl;
cout << "tChain: " << Info.chain << endl;
cout << "tIssuer: " << Info.issuer << endl;
cout << "tServer: " << Info.server << endl;
cout << "tCert date from: " << ctime(&tm);
cout << "tCert date to: " << ctime(&tm_to);
cout << "tProtocol: " << Info.protocol << endl;
cout << "tCipher: " << Info.cipher << endl;
cout << "tMAC: " << Info.mac << endl;
cout << "tCompression: " << Info.compression << endl;
cout << "t========================================" << endl;
return true;
}
virtual void handleMessage( const Message& stanza,
MessageSession* session = 0 ){
Message msg(Message::Chat, stanza.from(), "hello world" );
client->send( msg );
}
private:
Client* client;
};
int main( int argc, char* argv[] ){
cout << "1" << endl;
Bot b;
}
在控制台中打印证书不受信任证书没有已知的颁发者但是onTLSConnect总是返回true,所以它至少应该是在线的。。。至少应打印"it is connected good:)"
检查您的代码,onTLSConnect
只有一个return
语句,那就是末尾的return true;
。它从不在任何地方返回false
。
相关文章:
- 我的神经网络不起作用 [XOR 问题]
- 在C++程序中输入的文本文件将不起作用,除非文本被复制和粘贴
- C++映射:具有自定义类的运算符[]不起作用(总是返回0)
- C++为什么尽管我调用了void函数,它却不起作用
- 为什么在保护模式下继承升级不起作用
- 循环在计数器中不起作用
- 在其他文件中创建类时在 c++ 项目中不起作用
- Visual studio代码重构似乎不起作用(例如,重命名符号-f2)
- 为什么二进制搜索在我的测试中不起作用
- 我的代码中有错误吗?使用BGI图形的C++代码对我不起作用
- 为什么 const std::p air<K,V>& 在 std::map 上基于范围的 for 循环不起作用?
- 带有指定长度字符* 参数的 std::regex_search 在 VS2017 中不起作用?
- Bjarne Stroustrup Book - std_lib_facilities.h - 不起作用(未知类型名称)
- 为什么简单的算术减法在"if"条件下不起作用?
- 为什么Stroustup书中的has_f不起作用
- 你能检查一下为什么在这个代码中从链接列表中删除项目不起作用吗
- 嵌套While循环不起作用(C++问题)
- C++Matching Brackets 2解决方案不起作用
- 为什么这段代码不起作用,我该如何解决?
- 为什么glox不起作用