我在使用 emscripten 连接到原始 TCP 服务器表单编译的 Web 应用程序时遇到问题。当我从桌面版本的应用程序连接时,一切都很好。
在我的 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
有人知道吗?