c++ - wxHTTP 和线程

标签 c++ multithreading wxwidgets wxhttp

我在线程内使用 wxHTTP 时遇到了一些问题。我创建了以下派生自 wxThread 的类以使用 wxHTTP。

class Thread : public wxThread {
private:
wxHTTP get;

public:
Thread()
{
}
~Thread()
{
}

virtual ExitCode Entry()
{

    get.SetHeader(wxT("Content-Type"), wxT("text/html; charset=utf-8"));
    get.Connect(wxT("www.mysite.com"));

    get.SetTimeout(1);

    wxInputStream *httpStream = get.GetInputStream(wxT("/script.php?name=aaa&text=blabla"));
    wxDELETE(httpStream);
    get.Close();


    return 0;
}
};

我创建了这个线程并运行它(线程被创建、运行并且一切正常)。不幸的是,wxHTTP 似乎无法与线程一起正常工作(即使我的防火墙也不会询问我有关连接的信息)。有什么方法可以在线程内创建 wxHTTP 连接吗?

最佳答案

这是答案(根据@bluefeet 的要求) wxHTTP 继承自 wxSocketBase 并且在 wxSocketBase 中我们有这个引用

When using wxSocket from multiple threads, even implicitly (e.g. by using wxFTP or wxHTTP in another thread) you must initialize the sockets from the main thread by calling Initialize() before creating the other ones.

参见 here更多解释

关于c++ - wxHTTP 和线程,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10067056/

相关文章:

linux - WX_CONFIG_OPTIONS : command not found

C++11增加原子变量,赋值给其他值,是原子操作吗?

c++ - 在 Ubuntu 中获取 CPU 时间?

c++ - 改善多线程通信?

java - Java 中的多线程不考虑套接字超时?

python - 如何在 wxPython 静态文本小部件中显示插入符号?

c++ - Cython:共享对象中 undefined symbol

multithreading - 识别linux内核模块中的错误

ios - 如何检查调度队列是否为空?

c++ - wxWidgets 和 NetBeans : Does not recognize files in "include"