Socket IO connection issue

coolestbnslzHOBBY

3 months ago

I created express and io app in nodejs on the same port. While testing with script i am getting error.
Error: write EPROTO 8085110801000000:error:0A0000C6:SSL routines:tls_get_more_records:packet length too long:ssl/record/methods/tls_common.c:649:

Testing Script:

const io = require('socket.io-client');
const socket = io('https://flit-core-backend-production.up.railway.app', {    transports: ['polling', 'websocket'], // Start with polling, upgrade to websocket
    reconnection: true,
    reconnectionAttempts: 5,
    reconnectionDelay: 1000,
    reconnectionDelayMax: 5000,
    timeout: 20000,
    autoConnect: true,
    forceNew: true,
    path: '/socket.io/',
    withCredentials: true,
    secure: true,
    rejectUnauthorized: false, // Only if using self-signed certificates
    // Additional options for handling large packets
    maxHttpBufferSize: 1e6, // 1MB
    // Disable compression
    perMessageDeflate: false });


socket.on('connect', () => {
    console.log('Connected:', socket.id);
    socket.emit('rider:online', '12345'); // Test event
});

socket.on('order:new', (data) => {
    console.log('New Order:', data);
});

socket.on("connect_error", (err) => {
    // the reason of the error, for example "xhr poll error"
    console.log(err.message);
  
    // some additional description, for example the status code of the initial HTTP response
    console.log(err.description);
  
    // some additional context, for example the XMLHttpRequest object
    console.log(err.context);
  });

The Socket is created like this

const initializeSocket = (server) => {
    io = new Server(server,{
        path: '/socket.io/',
        transports: ['websocket', 'polling'], // Allow fallback to polling
    });

    io.on('connection', (socket) => {
        logInfo('Client connected to socket', 'SOCKET_CONNECTION', {
            socketId: socket.id
        });

        io.on('rider:online', (riderId) => {
            socket.join(`rider:${riderId}`);
            logInfo('Rider connected', 'RIDER_SOCKET_CONNECTED', {
                riderId,
                socketId: socket.id
            });
        });

        io.on('user:online', (userId) => {
            socket.join(`user:${userId}`);
            logInfo('User connected', 'USER_SOCKET_CONNECTED', {
                userId,
                socketId: socket.id
            });
        });

        io.on('disconnect', () => {
            logInfo('Client disconnected from socket', 'SOCKET_DISCONNECTION', {
                socketId: socket.id
            });
        });
    });

    return io;
};

3 Replies

3 months ago

You mentioned it’s on the same port. What happens when you deploy only the SocketIO WS on a separate server without the express piece?


Status changed to Awaiting User Response railway[bot] 3 months ago


coolestbnslzHOBBY

3 months ago

but, i want the same functionality and codebase is same. Need to trigger event when anyone hits the api.


Status changed to Awaiting Railway Response railway[bot] 3 months ago


coolestbnslzHOBBY

3 months ago

I started the socket app with another port. but now i am getting ECONNRESET for new port


Socket IO connection issue - Railway Help Station