- iOS/Objective-C 元类和类别
- objective-c - -1001 错误,当 NSURLSession 通过 httpproxy 和/etc/hosts
- java - 使用网络类获取 url 地址
- ios - 推送通知中不播放声音
我在使用 emscripten 从已编译的 Web 应用程序连接到原始 TCP 服务器时遇到问题。当我从应用程序的桌面版本连接时,一切都很好。
在我的 VPS 上,我通过以下方式下载、编译和运行 websockify:
./websockify 0.0.0.0:1235 127.0.0.1:1234
接下来我编译并运行我的服务器,代码:http://pastebin.com/KiehDrvk (来自BeeJ网络)
我的客户端代码非常简单(仅用于测试目的),一些代码:
TCPsocket sock;
struct sockaddr_in sock_addr;
/* Allocate a TCP socket structure */
sock = (TCPsocket)malloc(sizeof(*sock));
if ( sock == NULL ) {
SDLNet_SetError("Out of memory");
goto error_return;
}
/* Open the socket */
sock->channel = socket(AF_INET, SOCK_STREAM, 0);
if ( sock->channel == INVALID_SOCKET ) {
SDLNet_SetError("Couldn't create socket");
goto error_return;
}
/* Connect to remote, or bind locally, as appropriate */
if ( (ip->host != INADDR_NONE) && (ip->host != INADDR_ANY) ) {
// ######### Connecting to remote
memset(&sock_addr, 0, sizeof(sock_addr));
sock_addr.sin_family = AF_INET;
sock_addr.sin_addr.s_addr = ip->host;
sock_addr.sin_port = ip->port;
/* Connect to the remote host */
if ( connect(sock->channel, (struct sockaddr *)&sock_addr, sizeof(sock_addr)) == SOCKET_ERROR && errno != EINPROGRESS ) {
SDLNet_SetError("Couldn't connect to remote host");
goto error_return;
}
while (1);
}
所以当我在桌面上运行它时,客户端连接到服务器并按预期等待。
服务器终端返回:
selectserver: new connection from 91.211.105.49 on socket 5
Websockify 终端返回:
None because is from desktop
但是当我尝试从网络版本连接时,客户端连接并突然断开连接:
服务器终端返回:
selectserver: new connection from 127.0.0.1 on socket 6
selectserver: socket 6 hung up
hung up: Success
Websockify 终端返回:
1: got client connection from 91.211.105.49
1: forking handler process
1: using plain (not SSL) socket
1: using protocol HyBi/IETF 6455 13
1: connecting to: 127.0.0.1:1234
1: client closed connection
1: handler exit
有人知道吗?
最佳答案
您必须允许您的代码返回到网络浏览器运行时。您有一个 while(1) 永恒循环,我怀疑您的浏览器由于无响应而终止了您的应用程序?
如果您正在使用 Emscriptem 建议的主循环设计 (https://kripken.github.io/emscripten-site/docs/porting/emscripten-runtime-environment.html#implementing-an-asynchronous-main-loop-in-c-c),您只需将变量移动到全局范围并从代码中删除 while(1) 循环。
// (1) put all your variables here (global scope)
int main() {
// (2) put your connect code here (without the while(1) loop)
#ifdef __EMSCRIPTEN__
// void emscripten_set_main_loop(em_callback_func func, int fps, int simulate_infinite_loop);
emscripten_set_main_loop(one_iter, 60, 1);
#else
while (1) {
one_iter();
// Delay to keep frame rate constant (using SDL)
SDL_Delay(time_to_next_frame());
}
#endif
}
// The "main loop" function.
void one_iter() {
// process input
// render to screen
}
这至少可以让您在浏览器中测试您的代码。祝你好运!
关于c++ - Emscripten -> websockify -> raw tcp 意外挂断,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/38383200/
我需要将什么添加到我的 CMakeLists.txt 文件中,以便下面的示例来自 here还能建吗? 我可以毫无问题地生成 WASM,但不知道要在我的 CMakeLists.txt 中添加什么以停止出
我很好奇 emscripten 是否可以在没有 libc 的情况下构建二进制文件。 如果我有 simple.c: int add1(int x) { return x + 1; } 而且我不想
我已经研究了一段时间,我似乎无法找到如何实现这一点。 有一个非常明确的标题 emscripten_get_canvas_size,它没有做我期望它做的事情。实际的 Emscripten Canvas
Emscripten 教程很好地解释了如何与 C 函数交互:https://github.com/kripken/emscripten/wiki/Interacting-with-code 但是你如何
我对 WebAssembly 非常感兴趣,但我感到沮丧的是,即使是用 C++ 编码并使用 Emscripten 编译的“Hello World”示例,也会在浏览器中加载总共 396KB。是什么赋予了?
game engine我用来运行我的 game在浏览器中运行 lua 并在我的游戏中使用正常的 fopen/write/fclose 保存文件。引擎C/C++代码通过emscripten编译为JS。让
当使用不带任何参数的 emscripten 编译 C++ 时,除了 webgl Canvas 之外,它还会生成一个带有控制台和 emscripten Logo 的 html 文件。 是否可以禁用 Lo
我在 emscripten 中有一个 hello world 代码。如果可能的话,我想用 visual studio code 调试它并设置断点和调试更容易。我尝试这样做,但我无法在断点处停止。我使用
我正在阅读这里的 emscripten 教程 - https://github.com/kripken/emscripten/wiki/Tutorial 到目前为止,我已经下载了源代码并安装了依赖项并
是否可以使用 Emscripten 优化构建/编译 Opus/libopus?我不确定这是否是 Emscripten 和 WebAssembly 的一般当前限制,或者是否存在确保解码器在 WebAss
在 Emscripten wiki ( Interacting with code ) 中,只有两种类型被列为要传递给 ccall 的可能返回类型。或 cwrap (“数字”和“字符串”)。如何包装/
如何使用 emcmake cmake 并传递 emscripten 命令行选项? C++/CMake 的新手,但在谷歌上找不到任何有用的东西。所以也许这个问题只是愚蠢的,在那种情况下我道歉。 我可以使
我是 opencv.js 的新手。我在构建 opencv.js 时遇到了一些问题我正在使用 Windows 10。我按照以下步骤设置 opencv.js https://docs.opencv.org
我无法在另一个 JavaScript 文件中调用 C 函数,它给出了错误“在运行时初始化之前调用”please refer to this link 我按照给定链接中的描述在 emscripten 中
我正在尝试使用 Emscripten 构建一个使用 ffmpeg 库到 WebAssembly 的小项目。在此之前,我通过将一些简单的程序从 C 转换为 Wasm 来进行尝试,它运行良好,但那时我没有
我正在尝试将线程与 Emscripten 一起使用,但我不明白它是如何工作的。我已经阅读了一些关于网络 worker 的文字,但我不确定是否理解。 当我查看“tests”文件夹时,I can see
我正在运行一个使用 emscripten 编译为 wasm 的 C 工具。该工具适用于非常大的文件。在 CLI 上正常运行此工具时,操作通常会流式传输结果并在返回足够的数据后提前终止程序。例如,您可能
Mono 有一个 LLVM编译器。无论如何可以将它与 Emscripten 一起使用吗? (将 C# 代码编译为 JavaScript)? 最佳答案 目前没有现成的方法可以做到这一点。这也许是可能的,
我通过以下步骤安装了 Emscripten: 1.) Download the emsdk-portable version for Linux/MacOSX http://kripken.githu
我是 Emscripten/javascript 的新手,如果我的情况已经得到解决,我提前道歉。我在 ionic3 中有一个应用程序,我想读取 c 中有 3 个位置的数组,这个位置有其他数组,在结构上
我是一名优秀的程序员,十分优秀!