小编Koo*_*chi的帖子

使用unicode路径打开文件

我正在使用mingw在Windows 7下工作.我遇到了一些unicode文件名的怪异行为.我的程序需要是可移植的,我正在使用它boost::filesystem (v 1.53)来处理文件路径.

这一直进展顺利,直到我需要打开带有unicode文件名的文件.这不是文件的内容,而是文件的名称.

我尝试了以下内容:为了测试C:\UnicodeTest\????????,我创建了一个名为的文件夹,我尝试在其中创建一个文件,方法是将文件名附加test.txt到boost wpath.由于某种原因,文件的创建失败.我正在使用boost的fstream,当我尝试打开文件时,设置了流的failbit.现在有趣的是,当我将foldername追加到路径时,调用create_directories()成功并创建正确的目录C:\UnicodeTest\????????\folder.

我真的不明白为什么它不适用于文件.这是我使用的代码:

boost::filesystem::wpath path;

// find the folder to test
boost::filesystem::wpath dirPath = "C:\\UnicodeTest";
vector<boost::filesystem::wpath> files;
copy(boost::filesystem::directory_iterator(dirPath), boost::filesystem::directory_iterator(), back_inserter(files));

for(boost::filesystem::wpath &file : files)
{
    if(boost::filesystem::is_directory(file))
    {
        path = file;
        break;
    }
}

// create a path for the folder
boost::filesystem::wpath folderPath = path / "folder";
// this works just fine
boost::filesystem::create_directories(folderPath);

// create a path for the file
boost::filesystem::wpath filePath = path …
Run Code Online (Sandbox Code Playgroud)

c++ unicode boost

5
推荐指数
1
解决办法
3456
查看次数

使用websocketpp库连接到c ++ websocket服务器

我正在研究Ubuntu,我正在编写一个使用websocket ++库的c ++服务器,它非常适合来自浏览器的传入websocket连接(我在那里使用javascript).

现在我想做一些性能测试并连接很多自动化的'假'客户端.

为此,我想编写一个多次启动并连接到该服务器的程序.为此,我尝试了以下代码:

#include "websocketpp/src/roles/client.hpp"
#include "websocketpp/src/websocketpp.hpp"

#include <boost/asio.hpp>
#include <boost/bind.hpp>
#include <boost/thread.hpp>

#include "FakeClient.h"

using boost::asio::ip::tcp;
using websocketpp::client;


FakeClient::FakeClient()
{
    thisPointer = boost::shared_ptr<FakeClient>(this);

    client endpoint(thisPointer);

    endpoint.alog().unset_level(websocketpp::log::alevel::ALL);
    endpoint.elog().unset_level(websocketpp::log::elevel::ALL);

    endpoint.elog().set_level(websocketpp::log::elevel::RERROR);
    endpoint.elog().set_level(websocketpp::log::elevel::FATAL);

    endpoint.connect("ws://localhost:9001/");

    boost::thread t(&FakeClient::run, *this);

    t.join();
}

void FakeClient::run()
{
    while(true)
    {
        // send stuff here
        usleep(100);
    }
}
Run Code Online (Sandbox Code Playgroud)

现在,当服务器启动并且假客户端尝试连接时,我只会收到以下错误:

2013-04-23T16:00:02 [2] fail_on_expire timer expired with message: Timeout on WebSocket handshake
Run Code Online (Sandbox Code Playgroud)

但是,当服务器未启动时,不会显示任何错误消息,因此肯定会发生某种连接.但我无法弄清楚我做错了什么.是否可以通过websocket ++ lib轻松连接2个二进制程序?

为了获得最佳性能测试结果,我认为应该使用websockets进行服务器和假客户端之间的通信.

谢谢您的帮助,

Koonschi

c++ websocket++

2
推荐指数
1
解决办法
7296
查看次数

标签 统计

c++ ×2

boost ×1

unicode ×1

websocket++ ×1