Skip to content

Connection keep closing on React Native #632

Description

@seungholee-dev

Environment

  • Frontend: React Native
  • Backend: Spring with STOMP
  • React Native Version: v13.6.6
  • stompjs Version: v.7.4.0

Issue

  • The logs keep showing me the connection is opened and closed immediately.
  • I saw documentations about React Native issues but had no chance after setting below:
    • text-encoding
    • appendMissingNullonIncoming: true
    • forceBinaryWSFrames: true
    • Also tried downgrading to 5.4.0 where community says it worked but didn't for me
 LOG  Opening Web Socket...
 LOG  Connection closed to ws://localhost:8080/ws
 LOG  STOMP: scheduling reconnection in 5000ms

Code

websocket.js

import { Client } from '@stomp/stompjs';

const socketUrl = 'ws://localhost:8080/ws';

export const connectWebSocket = () => {
    let client = new Client({
        brokerURL: socketUrl,
        debug: (str) => {
            console.log(str);
        },
        appendMissingNULLonIncoming: true,
        forceBinaryWSFrames: true,
        onConnect: () => {
            console.log('Connected');
        },
    });

    client.activate();
}

App.jsx

import * as encoding from 'text-encoding';
import {connectWebSocket} from "./src/config/websocket";

Object.assign(global, encoding)

 useEffect(() => {
     connectWebSocket();
 }, []);

Have I been doing anything wrong?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions