Skip to content
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

[error] consume error: websocketpp.processor:9 (Invalid use of reserved bits) #384

Open
8Observer8 opened this issue Dec 25, 2022 · 1 comment

Comments

@8Observer8
Copy link

8Observer8 commented Dec 25, 2022

I tried to connect locally but got this error:

OpenGL Version: 3.1.0 - Build 9.17.10.4459
[2023-01-05 13:27:08] [connect] Successful connection
[2023-01-05 13:27:08] [connect] WebSocket Connection 127.0.0.1:3000 v-2 "WebSocket++/0.8.2" /socket.io/?EIO=3&transport=websocket&t=1672910828 101
[2023-01-05 13:27:08] [error] consume error: websocketpp.processor:9 (Invalid use of reserved bits)
[2023-01-05 13:27:08] [disconnect] Disconnect close local:[1002,Invalid use of reserved bits] remote:[1006]
[2023-01-05 13:27:13] [connect] Successful connection
[2023-01-05 13:27:13] [connect] WebSocket Connection 127.0.0.1:3000 v-2 "WebSocket++/0.8.2" /socket.io/?EIO=3&transport=websocket&t=1672910833 101
[2023-01-05 13:27:13] [error] consume error: websocketpp.processor:9 (Invalid use of reserved bits)
[2023-01-05 13:27:13] [disconnect] Disconnect close local:[1002,Invalid use of reserved bits] remote:[1006]

main.cpp

#include <glad/glad.h>
#include <iostream>

#define SDL_MAIN_HANDLED
#include <SDL2/SDL.h>

#define SIO_TLS
#include <sio_client.h>

const int WIDTH = 400, HEIGHT = 400;
const float maxFPS = 60.f;

int main()
{
    // Init SDL2
    if (SDL_Init(SDL_INIT_VIDEO) < 0)
    {
        std::cout << SDL_GetError << std::endl;
        exit(EXIT_FAILURE);
    }

    SDL_GL_SetAttribute(SDL_GL_DOUBLEBUFFER, 1);

    SDL_Window *window = SDL_CreateWindow("CG_P4", SDL_WINDOWPOS_CENTERED,
        SDL_WINDOWPOS_CENTERED, WIDTH, HEIGHT, SDL_WINDOW_OPENGL);
    if (!window)
    {
        std::cout << SDL_GetError << std::endl;
        SDL_Quit();
        exit(EXIT_FAILURE);
    }

    SDL_GLContext glContext = SDL_GL_CreateContext(window);
    if (!glContext)
    {
        std::cout << SDL_GetError << std::endl;
        SDL_Quit();
        exit(EXIT_FAILURE);
    }

    // Initialize GLAD to set up the OpenGL Function pointers
    if (!gladLoadGL())
    {
        std::cout << "Failed to initialize the GLAD library" << std::endl;
        SDL_Quit();
        exit(EXIT_FAILURE);
    }

    std::cout << "OpenGL Version: " << glGetString(GL_VERSION) << std::endl;

    // Set background color
    glClearColor(0.875f, 0.875f, 0.875f, 0.f);

    // Define the viewport dimensions
    glViewport(0, 0, WIDTH, HEIGHT);

    sio::client h;
    h.connect("https://127.0.0.1:3000");
    // h.connect("wss://connection-js.onrender.com/");
    // h.connect("wss://hungry-mighty-hospital.glitch.me");

    bool running = true;
    while (running)
    {
        SDL_Event event;

        while (SDL_PollEvent(&event))
        {
            switch (event.type)
            {
                case SDL_QUIT:
                    running = false;
                    break;
            }
        }
        float startTicks = SDL_GetTicks();

        glClear(GL_COLOR_BUFFER_BIT);

        SDL_GL_SwapWindow(window);

        // Limit FPS to the max FPS
        float frameTicks = SDL_GetTicks() - startTicks;
        if (1000.f / maxFPS > frameTicks)
        {
            SDL_Delay(1000.f / maxFPS - frameTicks);
        }
    }

    return 0;
}

app.js:

const express = require("express");
const io = require("socket.io")();
const http = require("http");
const path = require("path");

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

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

sio.sockets.on("connection", (socket) => {
    console.log("client was connected");
});
@8Observer8 8Observer8 changed the title Server handshake response error: websocketpp.processor:20 My stupid mistake guys. Please, delete it. Dec 26, 2022
@8Observer8 8Observer8 changed the title My stupid mistake guys. Please, delete it. My stupid mistake, guys. Please, delete it. Dec 26, 2022
@8Observer8 8Observer8 reopened this Jan 5, 2023
@8Observer8 8Observer8 changed the title My stupid mistake, guys. Please, delete it. [error] consume error: websocketpp.processor:9 (Invalid use of reserved bits) Jan 5, 2023
@8Observer8
Copy link
Author

8Observer8 commented Jan 5, 2023

It should be noted that the connection occurs if ws is used on the server side instead of socket.io

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

const app = express();
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");
});
[2023-01-05 19:46:30] [connect] Successful connection
[2023-01-05 19:46:30] [connect] WebSocket Connection 127.0.0.1:3000 v-2 "WebSocket++/0.8.2" /socket.io/?EIO=3&transport=websocket&t=1672933590 101

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant