精华内容
下载资源
问答
  • uWebSocket supicious ?

    2021-01-12 02:35:17
    <p>You inform me that the is some stories about <code>uWebSocket</code> https://medium.com//beware-of-uwebsockets-js-b51c92cac83f </p> <p>Thanks for notification :stuck_out_tongue: <p>/cc <p>The ...
  • uWebSocket http

    千次阅读 2018-10-17 17:54:03
    uWebSocket是支持http请求的,不过比较粗糙吧。 template &lt;bool isServer&gt; void Group&lt;isServer&gt;::onHttpRequest(std::function&lt;void (HttpResponse *, HttpRequest, char *, ...

    uWebSocket是支持http请求的,不过比较粗糙吧。

    template <bool isServer>
    void Group<isServer>::onHttpRequest(std::function<void (HttpResponse *, HttpRequest, char *, size_t, size_t)> handler) {
        httpRequestHandler = handler;
    }

     

    处理请求后,返回给浏览器,报错。

    Access-Control-Allow-Origin 跨域请求

     

    在“HTTPSocket.h”第207行中,修改一下,加入应答头“Access-Control-Allow-Origin”

    int offset = transformData.hasHead ? 0 : std::sprintf(dst, "HTTP/1.1 200 OK\r\nAccess-Control-Allow-Origin:*\r\nContent-Length: %u\r\n\r\n", (unsigned int) length);//Access-Control-Allow-Origin 跨域请求

    还有就是,收到的消息中文乱码。

    C++ 中自己 Url 解码,然后从utf-8转一下就好。

    unsigned char ToolClass::ToHex(unsigned char x)
    	{
    		return  x > 9 ? x + 55 : x + 48;
    	}
    	//------------------------------------------------------------------
    	unsigned char ToolClass::FromHex(unsigned char x)
    	{
    		unsigned char y;
    		if (x >= 'A' && x <= 'Z') y = x - 'A' + 10;
    		else if (x >= 'a' && x <= 'z') y = x - 'a' + 10;
    		else if (x >= '0' && x <= '9') y = x - '0';
    		//else assert(0);
    		return y;
    	}
    	//------------------------------------------------------------------
    	std::string ToolClass::UrlEncode(const std::string& str)
    	{
    		std::string strTemp = "";
    		size_t length = str.length();
    		for (size_t i = 0; i < length; i++)
    		{
    			if (isalnum((unsigned char)str[i]) ||
    				(str[i] == '-') ||
    				(str[i] == '_') ||
    				(str[i] == '.') ||
    				(str[i] == '~'))
    				strTemp += str[i];
    			else if (str[i] == ' ')
    				strTemp += "+";
    			else
    			{
    				strTemp += '%';
    				strTemp += ToHex((unsigned char)str[i] >> 4);
    				strTemp += ToHex((unsigned char)str[i] % 16);
    			}
    		}
    		return strTemp;
    	}
    	//------------------------------------------------------------------
    	std::string ToolClass::UrlDecode(const std::string& str)
    	{
    		std::string strTemp = "";
    		size_t length = str.length();
    		for (size_t i = 0; i < length; i++)
    		{
    			if (str[i] == '+') strTemp += ' ';
    			else if (str[i] == '%')
    			{
    				//assert(i + 2 < length);
    				if (i + 2 < length)
    				{
    					unsigned char high = FromHex((unsigned char)str[++i]);
    					unsigned char low = FromHex((unsigned char)str[++i]);
    					strTemp += high * 16 + low;
    				}
    			}
    			else strTemp += str[i];
    		}
    		return strTemp;
    	}

     

    展开全文
  • uWebSocket源码

    2019-03-29 15:02:40
    使用c++创建websocket客户端服务端的三方代码,使用简单,包含依赖的libuv库
  • The method signature for uWebsocket doesn't match the header file. I provided a fix which compile successfully on Ubuntu, can someone confirm it still compiles on Windows and Mac?</p><p>该提问...
  • <div><ul><li>Fixed builtin uwebsocket module import.</li><li>Fixed server handshake. Add extra '\r\n' after last header line to indicate end of the header. Without it websocket server doesn&#...
  • Use uWebSocket

    2020-12-02 01:03:49
    <div><p>该提问来源于开源项目:logux/server</p></div>
  • libuv与uWebSocket 掉坑之旅

    千次阅读 2018-09-21 09:15:10
    libuv和uWebSocket都是开源的,这一点很棒。 libuv是Node.js的内核,强大、简洁、优雅。 uWebSocket浅浅的封装了libuv,改装成websocket版(仅仅用了少量的libuv的东西)。 掉坑之旅开始:上周一切完美的事情,...

    libuvuWebSocket都是开源的,这一点很棒。

    libuv是Node.js的内核,强大、简洁、优雅。

    uWebSocket浅浅的封装了libuv,改装成websocket版(仅仅用了少量的libuv的东西)。

    掉坑之旅开始:上周一切完美的事情,周一发生了转折。客户端和服务端在同一台机器上,客户端连接服务端,竟然需要1分钟左右才能连接上,拔掉网线,瞬间就连上了。这也太神奇了吧。一大堆业务逻辑,还是多线程,找起来真费劲,头皮发麻。小伙伴说是不是中毒了,一扫真的有毒。杀毒3小时后,还是一样的效果。痛定思痛,认真划分模块,一点点测试,终于找到了,原来服务端还需要连接一个远端的服务器,而这个服务器端口改了。

    查看源码发现:uWebSocket 没有直接用Libuv封装的完成端口,自己又整了一套,其中:

    ::connect(fd, result->ai_addr, result->ai_addrlen);

    这一句阻塞5秒左右。完成端口也没用多线程,这一句:

    success = GetQueuedCompletionStatusEx

    又阻塞5秒,再加上断线重连,其他的客户端根本没机会连上来。

     

    找到问题,修改就容易了。

    展开全文
  • Thor with uWebSocket

    2020-12-06 01:49:15
    <div><p>See the issue on the uWebSockets project for details: https://github.com/uWebSockets/uWebSockets/issues/371</p> <p>Sadly the communication is not going very smoothly and the author of ...
  • <div><p>Hi I could not find a place to quest under uWebsocket, so I post it here: On winodws 10, while calling hub.connect to wws, it will block several seconds. if I add predefine SOCK_CLOEXEC;SOCK_...
  • <div><h2>DESC <p>Highly scalable WebSocket server & client library: ...<p><code>10-300x faster than ws</code> <p>all need to do: <pre><code> js var io = require('socket.io'...
  • <div><p>Project https://github.com/uNetworking/uWebSockets.js</p><p>该提问来源于开源项目:moleculerjs/moleculer-web</p></div>
  • <div><p>P2P technologies should be scalable and efficient when it goes to high loads. ...<p>This <a href="https://levelup.gitconnected.com/will-node-js-forever-be-the-sluggish-golang-f632130e5c7a">...
  • C++学习开源项目

    2020-06-10 10:21:46
    C++学习开源项目相关开源项目filezillauWebSocket 网络库TeamTalk 相关开源项目 filezilla svn下载地址 uWebSocket 网络库 github下载地址 TeamTalk 蘑菇街内部通讯工具 GitHub下载地址

    相关开源项目

    filezilla

    svn下载地址

    uWebSocket 网络库

    github下载地址

    TeamTalk

    蘑菇街内部通讯工具
    GitHub下载地址

    gh0st

    远程控制
    GitHub下载地址

    展开全文
  • Introduce variants

    2021-01-12 02:12:49
    <div><p>Using <code>low</code> HTTP server (friendly Node.js wrapper around uWebSocket.js) Big performance gain!</p><p>该提问来源于开源项目:the-benchmarker/web-frameworks</p></div>
  • either programmatically or by environment variable, the reason being the availability of the <a href="https://github.com/alexhultman/uWebSockets">uWebSocket alternative</a> - which will eventually ...
  • Pub sub, Crashing errors

    2021-01-09 03:14:23
    re from the uWebSocket C++ library. <p>Is there any way to enable more verbosity or investigate where they come from?</p><p>该提问来源于开源项目:uNetworking/uWebSockets.js</p></div>
  • C++11笔记

    2019-12-02 18:47:32
    在使用uWebSocket的时候 用到了大量的c++11 特性,在次稍微做下笔记: 1.std::aray 除了有传统数组支持随机访问、效率高、存储大小固定等特点外,还支持迭代器访问、获取容量、获得原始指针等高级功能。而且它还不会...

    在使用uWebSocket的时候 用到了大量的c++11 特性,在次稍微做下笔记:
    1.std::aray
    除了有传统数组支持随机访问、效率高、存储大小固定等特点外,还支持迭代器访问、获取容量、获得原始指针等高级功能。而且它还不会退化成指针T *给开发人员造成困惑。
    例:
    std::array<int, 10> arr = {1,2,3,4,5,6,7,8,9,0};
    std::for_each(arr.begin(), arr.end(), [](int &i){i++;});
    for(auto i : arr){std::cout << i << " ";}

    std::for_each 和 for(auto i : arr) 也是一个特色,平时很少这样用,可能是我比较守旧。

    2.std::thread
    构造函数的例子:
    #include < thread>
    #include < chrono>
    using namespace std;
    void fun1(int n) //初始化构造函数
    {
    cout << “Thread " << n << " executing\n”;
    n += 10;
    this_thread::sleep_for(chrono::milliseconds(10));
    }
    void fun2(int & n) //拷贝构造函数
    {
    cout << “Thread " << n << " executing\n”;
    n += 20;
    this_thread::sleep_for(chrono::milliseconds(10));
    }
    int main()
    {
    int n = 0;
    thread t1; //t1不是一个thread
    thread t2(fun1, n + 1); //按照值传递
    t2.join();
    cout << “n=” << n << ‘\n’;
    n = 10;
    thread t3(fun2, ref(n)); //引用
    thread t4(move(t3)); //t4执行t3,t3不是thread
    t4.join();
    cout << “n=” << n << ‘\n’;
    return 0;
    }

    特色:
    fun1,fun2的区别
    this_thread::sleep_for 的使用
    chrono::milliseconds(10)
    ref(n)
    std::ref可以在模板传参的时候传入引用,否则无法传递,std::ref只是尝试模拟引用传递,并不能真正变成引用,在非模板情况下,std::ref根本没法实现引用传递,只有模板自动推导类型时,ref能用包装类型reference_wrapper来代替原本会被识别的值类型,而reference_wrapper能隐式转换为被引用的值的引用类型。

    join(); 不调用join结束的时候会报错。
    hread (thread&& x)
    move 构造函数,调用成功之后 x 不代表任何 thread 执行对象。
    thread (const thread&) = delete;
    (被禁用),意味着 thread 不可被拷贝构造。

    线程函数可以任意传,多个都可以;

    join 是让当前主线程等待所有的子线程执行完,才能退出。
    detach 脱离主线程的绑定,主线程挂了,子线程不报错,子线程执行完自动退出。

    thread::hardware_concurrency();//获取cpu核心个数

    复习一下time.h clock 的使用:
    long i = 10000000L;
    clock_t start = clock();
    while( i-- ) ;
    clock_t finish = clock();
    duration = (double)(finish - start) / CLOCKS_PER_SEC;

    CLOCKS_PER_SEC:每秒钟跳多少次
    #define CLOCKS_PER_SEC ((clock_t)1000) 即每秒钟跳1000次(毫秒),运行时间为 duration 秒。

    复习一下互斥量:
    #include< mutex>
    mutex m;
    m.lock();
    //同步内容
    m.unlock();
    亲测发现使用时间特别长64s。原因是大量的加解锁。

    原子变量:
    #include
    atomic_int num{ 0 };

    使用原子变量时间明显比互斥量快3到4倍18s。

    通过jion等待
    thread t1(run);
    1.join();
    thread t2(run);
    t2.join();

    时间540ms,非常快,但这样就是相当于单线程,即如果有共享东西多线程就会比单线程慢好多,因为要处理同步的东西。

    可变参数函数的参数列表:

    va_list ap;//指针
    va_start(ap, fun);//开始
    va_arg(vaList,char*)
    // vprintf(fun, ap);//调用
    //vsprintf
    //vsnprintf
    va_end(ap);

    参考文章:https://www.cnblogs.com/lidabo/p/7852033.html

    展开全文
  • ve just tried to install uWebSocket on Mac OS Sierra using <code>install-mac.sh</code> and got the following error: <pre><code> CMake Error at cmake_install.cmake:39 (file): file cannot create ...
  • make Command issue

    2020-11-27 09:11:23
    UWebsocket issue of not compiling .cpp file because of the absence of c++11 compiler in linux <h4>Observed behavior <p>What did you see happen? Please include relevant error messages and/or ...
  • cWS instead of uWS

    2021-01-11 01:26:52
    <p><code>uWS</code> is dead and <code>cWS</code> is the most mature successor and uses <code>uWebsocket</code> under the hood too. <p>I've tried to implement it by myself in server.js of engine.io...
  • <div><p>Specify library name and version: <strong>uwebsocket/18.3.0</strong></p> <p>Related to: https://stackoverflow.com/questions/64694269/getting-uwebsockets-for-visual-2017-via-conan</p> <ul><li>...

空空如也

空空如也

1 2
收藏数 21
精华内容 8
关键字:

uwebsocket