Hi again,

My server is now using Websocketpp to connect to Emscripten's regular 
sockets.
They communicate back and forth just fine on Firefox and Edge.

However, in Chrome, I get the following error:

> WebSocket connection to 'ws://127.0.0.1:2321/' failed: Error during 
> WebSocket handshake: Sent non-empty 'Sec-WebSocket-Protocol' header but no 
> response was received


Is this an Emscripten thing or a Websocketpp thing? I couldn't find any 
viable solutions online.

On Wednesday, July 25, 2018 at 2:30:04 PM UTC-5, Treyten Carey wrote:

> Thanks, I converted the server to a WebSocket compatible version using 
> cppWebSockets 
> with libwebsockets <https://github.com/mnisjk/cppWebSockets> as an 
> example and that was what I needed.
> Appreciate your help.
>
> On Tuesday, July 24, 2018 at 10:11:06 AM UTC-5, Treyten Carey wrote:
>>
>> I am porting my C++ application, which uses sockets, to HTML with 
>> Emscripten.
>>
>> Here is the code I took from a blog post 
>> <https://blog.squareys.de/emscripten-sockets/> in order to test 
>> different ways of connecting:
>> void connect(const std::string& host, int port) {
>>     int sock;
>>     bool connected;
>>
>>     sock = socket(PF_INET, SOCK_STREAM, IPPROTO_TCP);
>>     if(sock == -1) {
>>         Error("connect(): failed to create socket");
>>         return;
>>     }
>>     fcntl(sock, F_SETFL, O_NONBLOCK);
>>
>>     struct sockaddr_in addr;
>>     memset(&addr, 0, sizeof(addr));
>>     addr.sin_family = AF_INET;
>>     addr.sin_port = htons(port);
>>     if(inet_pton(AF_INET, host.c_str(), &addr.sin_addr) != 1) {
>>         Error("connect(): inet_pton failed");
>>         return;
>>     }
>>
>>     const int res = ::connect(sock, (struct sockaddr *)&addr, 
>> sizeof(addr));
>>     if(res == -1) {
>>         if(errno == EINPROGRESS) {
>>             Debug("connect(): Connection in progress");
>>
>>             /* Wait for connection to complete */
>>             fd_set sockets;
>>             FD_ZERO(&sockets);
>>             FD_SET(_data->socket, &sockets);
>>
>>             /* You should probably do other work instead of busy waiting 
>> on this...
>>                or set a timeout or something */
>>             while(select(sock + 1, nullptr, &sockets, nullptr, nullptr) 
>> <= 0) { Debug(std::to_string(errno)); }
>>
>>             connected = true;
>>
>>         } else {
>>             Error("Socket::connect(): connection failed");
>>             return;
>>         }
>>     } else {
>>         connected = true;
>>     }
>> }
>>
>> The socket gets stuck in an infinite loop of errno 115 (EINPROGRESS).
>>
>> My server successfully accept()'s the connection, but the Emscripten 
>> client cannot receive/send any data. If I don't check for select, the 
>> network console shows OK 200, but sending data results in "Error during 
>> WebSocket handshake: net::ERR_INVALID_HTTP_RESPONSE" (probably because 
>> without select(), it doesn't wait for EINPROGRESS to finish before trying 
>> to send).
>>
>> Has anyone successfully got sockets to work with Emscripten?
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"emscripten-discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to