uWebSockets的使用

Posted 风翼科技

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了uWebSockets的使用相关的知识,希望对你有一定的参考价值。

最近要使用WebSockets做实时推送,然后看到网上一篇文章

https://www.jianshu.com/p/64e36cd3ed1a

说uWebSockets如何如何好,就试一把

项目主页 https://github.com/uNetworking/uWebSockets

打开里面的vs项目文件,编译发现缺少uv.h

项目里面也没有说要依赖某个库,一查这个库可是鼎鼎大名的libuv

https://github.com/libuv/libuv

关于libuv的一些介绍https://blog.csdn.net/linuxandroidwince/article/details/72297630

决定自己编译一个库出来,libuv官方的文档说在win下编译,需要配置如下

### Windows

Prerequisites:

* [Python 2.6 or 2.7][] as it is required
  by [GYP][].
  If python is not in your path, set the environment variable `PYTHON` to its
  location. For example: `set PYTHON=C:Python27python.exe`
* One of:
  * [Visual C++ Build Tools][]
  * [Visual Studio 2015 Update 3][], all editions
    including the Community edition (remember to select
    "Common Tools for Visual C++ 2015" feature during installation).
  * [Visual Studio 2017][], any edition (including the Build Tools SKU).
    **Required Components:** "MSbuild", "VC++ 2017 v141 toolset" and one of the
    Windows SDKs (10 or 8.1).
* Basic Unix tools required for some tests,
  [Git for Windows][] includes Git Bash
  and tools which can be included in the global `PATH`.

To build, launch a git shell (e.g. Cmd or PowerShell), run `vcbuild.bat`
(to build with VS2017 you need to explicitly add a `vs2017` argument),
which will checkout the GYP code into `build/gyp`, generate `uv.sln`
as well as the necesery related project files, and start building.

```console
> vcbuild
```

Or:

```console
> vcbuild vs2017
```

To run the tests:

```console
> vcbuild test
```

To see all the options that could passed to `vcbuild`:

```console
> vcbuild help
vcbuild.bat [debug/release] [test/bench] [clean] [noprojgen] [nobuild] [vs2017] [x86/x64] [static/shared]
Examples:
  vcbuild.bat              : builds debug build
  vcbuild.bat test         : builds debug build and runs tests
  vcbuild.bat release bench: builds release build and runs benchmarks

1.配置python执行路径

2.下载build/gyp 由于git clone https://chromium.googlesource.com/external/gyp build/gyp 这个地址墙了,所以替换为https://github.com/nodejs/node-gyp

选取里面的node-gyp 的gyp目录拷贝到build/

屏蔽这句

echo git clone https://chromium.googlesource.com/external/gyp build/gyp
@git clone https://chromium.googlesource.com/external/gyp build/gyp
if errorlevel 1 goto gyp_install_failed
goto have_gyp

 运行 vcbuild.bat

生成libuv.lib
uWebSockets项目中添加D:opensourcelibuv-v1.23.2libuv-v1.23.2include

编译报错

无法打开包括文件: “openssl/opensslv.h”: No such file or directory

下载 https://github.com/openssl/openssl

也可以直接 直接下载安装文件,里面所有的头文件,库都有,一定要选全版本,不能选择轻版本 https://slproweb.com/products/Win32OpenSSL.html  

 

以上是关于uWebSockets的使用的主要内容,如果未能解决你的问题,请参考以下文章

uWebSockets的使用

如何使用 Visual Studio C++ 中的 uWebsockets?

使用 CMake 在 Windows 10 上构建 uWebSockets

C ++ uWebSockets在一个线程中集成了事件循环

如何在 uWebSockets.js 中获取套接字路径?

如何使用 axios 从前端调用 uWebSockets http 路由?