我有问题,连接到原始TCP服务器表单编译的网页应用程序与emscripten.当我从桌面连接时,应用程序的版本都很好。
在我的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 5Websockify终端返回:
None because is from desktop但是当我尝试连接表单web版本时,客户端连接和突然断开:
服务器终端返回:
selectserver: new connection from 127.0.0.1 on socket 6
selectserver: socket 6 hung up
hung up: SuccessWebsockify终端返回:
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有人知道吗?
发布于 2016-07-14 23:17:33
必须允许代码返回到web浏览器运行时。您有一段时间(1)永恒的循环,我怀疑您的浏览器杀死您的应用程序,因为没有反应?
如果您正在为主循环(https://kripken.github.io/emscripten-site/docs/porting/emscripten-runtime-environment.html#implementing-an-asynchronous-main-loop-in-c-c)使用Emscriptem建议的设计,您可以将变量移动到全局范围,并从代码中删除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
}这应该允许您至少在浏览器中测试代码。祝好运!
https://stackoverflow.com/questions/38383200
复制相似问题