Skip to content

Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.) #32

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
sudheer76235 opened this issue Sep 21, 2018 · 12 comments
Labels
Difficulty: Advanced Best for maintainers to address Need Info Further information has been requested Priority: High Must be fixed before next release Type: Bug Maintainers have validated that it is a real bug in the project code

Comments

@sudheer76235
Copy link

I'm getting this error! what to do now?
screenshot 2018-09-21_10-07-04-675

@madsurgeon
Copy link

madsurgeon commented Jan 22, 2019

I am seeing the same:

ws$connect()
[2019-01-22 13:36:08] [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)
[2019-01-22 13:36:09] [info] asio async_shutdown error: asio.ssl.stream:1 (stream truncated)
Client failed to connect: Invalid HTTP status.

There are two threads about this error in the underlying websocketpp library:
socketio/socket.io-client-cpp#150
zaphoyd/websocketpp#648

@alandipert
Copy link
Contributor

Thank you for the reports. Can you please provide the following additional information?

  1. Can you share the URL of the WebSocket endpoint you're attempting to connect to?
  2. Are you connecting via wss?
  3. If wss, is the certificate the server is supplying valid or invalid? The easiest way to test this is to open a page on the target server in Chrome or Firefox and seeing if it complains about the certificate.

I haven't seen or been able to reproduce this using any wss:// endpoints I've tried, so it's going to be hard to fix until we can narrow down exactly what makes the endpoints this pops up with different. So, thanks in advance for sharing as much information about the problematic endpoints as possible.

@alandipert alandipert self-assigned this Apr 24, 2019
@alandipert alandipert added Difficulty: Advanced Best for maintainers to address Need Info Further information has been requested Priority: High Must be fixed before next release Type: Bug Maintainers have validated that it is a real bug in the project code labels Apr 24, 2019
@chunqiulfq
Copy link

hi, I encountered this error message during the use of socket.io-client-cpp. The problem I encountered was that the ssl was not compiled, the https used when setting the url was wrong, and it returned to normal when I used http. Hope to be helpful to this problem .

@AlexanderPaniutin
Copy link

AlexanderPaniutin commented Jan 28, 2020

I faced the same problem when I shipped my solution to customer. Everything works on my side but fails with this error on customer.
The investigation revealed that my client was not able to connect to his server(same error) and his client was able to connect to my server. So the issue is not in client since my app was dependent only on libc++ only.
The issue was on a server side.

I had a server written in Python with Flask-Socketio using gevent. I reproduced the issue when I had a clean env and installed only packages that I was using: flask, flask-socketio, gevent. The error was happening to me as well. The issue got solved when I install gevent-websocket which was a finger-into-an-air solution.
I did not recompile the client but simply restarted the server.
Hope it helps.

@egoipse
Copy link

egoipse commented Feb 29, 2020

Hi... Any news about this issue???

@alandipert alandipert removed their assignment May 29, 2020
@MotivaoCrypto
Copy link

ws$connect()
[2021-08-10 12:42:43] [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)
[2021-08-10 12:42:43] [info] asio async_shutdown error: asio.ssl.stream:1 (stream truncated)
Client failed to connect: Invalid HTTP status.

@yashasweeyash
Copy link

For me using the encoded URL solved the problem.
I am not sure when I am going to find time to code a proper fix for this repository, but meanwhile following should help or at least send some of you in the right direction (hopefully).

if the problematic url is:
wss://ws.host.com/?api_key=someApiKeyContaining/+=Etc&enctoken=someEncTokenContaining/+=Etc

then following encoded url should work:
wss://ws.host.com/?api_key=someApiKeyContaining%2F%2B%3DEtc&enctoken=someEncTokenContaining%2F%2B%3DEtc

@ele6
Copy link

ele6 commented Nov 11, 2021

how can i use streaming-graph.facebook.com Live Comments link show error :20 (Invalid HTTP status.)

https://streaming-graph.facebook.com/{live-video-id}/live_comments?access_token=[user-access-token]

I put in the browser chrome functions well url always have token activated

@8Observer8
Copy link

8Observer8 commented Oct 6, 2022

I have the same error. I'm using Windows 10, MinGW 64-bit. I'm trying to connect to my server (see my server script below) which is hosted on the Render host at this address:

std::string uri = "wss://connection-js.onrender.com";

When I use "wss://..." I see this error: could not create connection because: endpoint not secure When I use "ws://..." I see these errors:

[2022-10-07 00:33:09] [connect] Successful connection
[2022-10-07 00:33:09] [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)
[2022-10-07 00:33:09] [fail] WebSocket Connection 216.24.57.3:80 - "WebSocket++/0.8.2" / 301 websocketpp.processor:20 Invalid HTTP status.

But this works locally:

std::string uri = "ws://localhost:3000";

I tried to connect my Qt6 client to this server - it works for "wss://..." but does not work for "ws://...".

main.cpp

#define ASIO_STANDALONE
#define _WEBSOCKETPP_CPP11_THREAD_
#define _WEBSOCKETPP_CPP11_RANDOM_DEVICE_
#define _WEBSOCKETPP_CPP11_STRICT_
#define _WEBSOCKETPP_CPP11_TYPE_TRAITS_

#include <websocketpp/config/asio_no_tls_client.hpp>
#include <websocketpp/client.hpp>

typedef websocketpp::client<websocketpp::config::asio_client> client;

using websocketpp::lib::placeholders::_1;
using websocketpp::lib::placeholders::_2;
using websocketpp::lib::bind;

// pull out the type of messages sent by our config
typedef websocketpp::config::asio_client::message_type::ptr message_ptr;

// This message handler will be invoked once for each incoming message. It
// prints the message and then sends a copy of the message back to the server.
void on_message(client* c, websocketpp::connection_hdl hdl, message_ptr msg) {
    std::cout << "on_message called with hdl: " << hdl.lock().get()
              << " and message: " << msg->get_payload()
              << std::endl;

    websocketpp::lib::error_code ec;

    c->send(hdl, msg->get_payload(), msg->get_opcode(), ec);
    if (ec) {
        std::cout << "Echo failed because: " << ec.message() << std::endl;
    }
}

int main()
{
    // Create a client endpoint
    client c;

    // std::string uri = "ws://localhost:3000";
    std::string uri = "wss://connection-js.onrender.com";

    try
    {
        // Set logging to be pretty verbose (everything except message payloads)
        c.set_access_channels(websocketpp::log::alevel::all);
        c.clear_access_channels(websocketpp::log::alevel::frame_payload);

        // Initialize ASIO
        c.init_asio();

        // Register our message handler
        c.set_message_handler(bind(&on_message,&c,::_1,::_2));

        websocketpp::lib::error_code ec;
        client::connection_ptr con = c.get_connection(uri, ec);
        if (ec)
        {
            std::cout << "could not create connection because: " << ec.message() << std::endl;
            return 0;
        }

        // Note that connect here only requests a connection. No network messages are
        // exchanged until the event loop starts running in the next line.
        c.connect(con);

        // Start the ASIO io_service run loop
        // this will cause a single connection to be made to the server. c.run()
        // will exit when this connection is closed.
        c.run();
    } catch (websocketpp::exception const & e)
    {
        std::cout << e.what() << std::endl;
    }

    return 0;
}

makefile

CC = g++

INC = -I"E:\Libs\websocketpp-0.8.2-headers" \
	  -I"E:\Libs\asio-1.24.0\include"

all: main.o
	$(CC) main.o -lws2_32 -o app

main.o: main.cpp
	$(CC) -c $(INC) main.cpp -o main.o

Server:

const express = require("express");
const http = require("http");
const ws = require("ws");
const path = require("path");

const app = express();
app.use(express.static(path.join(process.cwd(), "public")));

const httpServer = http.createServer(app);
const wss = new ws.Server(
{
    server: httpServer
});

const port = process.env.PORT || 3000;
httpServer.listen(port, () => console.log("Listening at port: " + port));

wss.on("connection", socket =>
{
	console.log("client was connected");
});

This is the Qt client that works:

main.cpp

#include <QtCore/QDebug>
#include <QtWidgets/QApplication>
#include <QtWidgets/QWidget>
#include <QtWebSockets/QWebSocket>

class Window : public QWidget
{
    Q_OBJECT

private:
    QWebSocket m_webSocket;

public:
    Window(QWidget *parent = nullptr)
        : QWidget(parent)
    {
        setWindowTitle("Qt6 C++ Client");
        resize(300, 300);

        connect(&m_webSocket, &QWebSocket::connected,
            this, &Window::onConnected);
        // m_webSocket.open(QUrl("ws://localhost:3000"));
        m_webSocket.open(QUrl("wss://connection-js.onrender.com"));
        qDebug() << "Waiting for connection...";
    }

private slots:

    void onConnected()
    {
        qDebug() << "Client was connected to server";
    }
};

#include "main.moc"

#ifdef _WIN32
#include <Windows.h>
#endif

int main(int argc, char *argv[])
{
#ifdef _WIN32
    if (AttachConsole(ATTACH_PARENT_PROCESS))
    {
        freopen("CONOUT$", "w", stdout);
        freopen("CONOUT$", "w", stderr);
    }
#endif

    QApplication a(argc, argv);
    Window w;
    w.show();
    return a.exec();
}

websocket-client-qt6-cpp.pro

# Build commands for CMD:
# qmake -makefile
# mingw32-make
# "./release/app"
 
QT += core gui widgets websockets

CONFIG += c++11
CONFIG += console
 
SOURCES += \
    main.cpp
 
TARGET = app

@8Observer8
Copy link

The problem endpoint not secure was solved here:

The error 'endpoint not secure' means the client instance is not one for TLS(endpoint is the base class of the client class).

So, use the configuration websocketpp::config::asio_tls_client instead of the websocketpp::config::asio_client. Also see the official sample, print_client_tls.cpp.

@jangorecki
Copy link

I am able to reproduce the error using examples from readme

library(websocket)

ws <- WebSocket$new("ws://echo.websocket.org/", autoConnect = FALSE)
ws$onOpen(function(event) {
  cat("Connection opened\n")
})
ws$onMessage(function(event) {
  cat("Client got msg: ", event$data, "\n")
})
ws$onClose(function(event) {
  cat("Client disconnected with code ", event$code,
    " and reason ", event$reason, "\n", sep = "")
})
ws$onError(function(event) {
  cat("Client failed to connect: ", event$message, "\n")
})
ws$connect()
[2023-10-25 12:41:07] [error] Server handshake response error: websocketpp.processor:20 (Invalid HTTP status.)
Client failed to connect:  Invalid HTTP status. 

@venkisathish
Copy link

any solution or hints like what needs to be changed to solve this issue

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Difficulty: Advanced Best for maintainers to address Need Info Further information has been requested Priority: High Must be fixed before next release Type: Bug Maintainers have validated that it is a real bug in the project code
Projects
None yet
Development

No branches or pull requests