JSteunou / webstomp-client

Stomp client over websocket for browsers
Apache License 2.0
299 stars 59 forks source link

React native: Cannot connect by android #62

Closed sy92th closed 6 years ago

sy92th commented 6 years ago

Hi JSteunou, my app use last version and client always return Whoops! Lost connection Can you help me ?

Mycode: const options = {debug: true, protocols: webstomp.VERSIONS.supportedProtocols()}; let client = webstomp.client(url, options); client.connect({}, function connectCallback(frame){ console.log('OK') }, (error) => { console.log('Error'); });

It work very good in ios but in android: Opening Web Socket... Web Socket Opened...

CONNECT accept-version:1.2,1.1,1.0 heart-beat:10000,10000 frame: { body: undefined, command: "CONNECT", headers: {accept-version: "1.2,1.1,1.0", heart-beat: "10000,10000"} } Whoops! Lost connection to undefined: {event: WebSocketEvent} WebSocketEvent {type: "close", target: WebSocket, currentTarget: WebSocket, eventPhase: 2, bubbles: false, …}

JSteunou commented 6 years ago

Sorry I dont know why it would not work specifically for this use case.

kashsbd commented 6 years ago

Hello JSteunou, It is not connecting to the websocket server.Plz, help me ! Here is my code, componentWillMount() { let msg = '';

    const options = { debug: true, protocols: webstomp.VERSIONS.supportedProtocols() }
    this.stompClient = webstomp.client("ws://192.168.3.167:8080/test", options)
    this.stompClient.connect({}, (frame) => {
        console.log("OK")
        this.stompClient.subscribe('/topic/greetings', (greeting) => {
            msg = JSON.parse(greeting.body);
        });
        this.setState({ connected: true, message: msg })
    }, (err) => console.log(err))

}

and logs...

Opening Web Socket... webstomp.js:243 Web Socket Opened... webstomp.js:243 >>> CONNECT accept-version:1.2,1.1,1.0 heart-beat:10000,10000

Thanks in advance.

JSteunou commented 6 years ago

Please do not pollute this issue if it is not related. I would like to keep this issue tracker for bugs or feature alike only. If need help try stackoverflow and such, thank you.

Dnyanoba-Kantode commented 6 years ago

I'm trying to connect our server. iOS is working fine but android is getting fail. Please help me here.

sy92th commented 6 years ago

Try to use SockJS

const SockJS = require('../libjs/sockjs.min');
const socket = new SockJS(url);
let stompClient = Stomp.over(socket);
// stompClient.debug = () => {};
const headers = {};
stompClient.connect(headers, (frame) => {
     console.log("OK");
})
tryhardest commented 4 years ago

sockJS is depreciated.