- SNIPPET -
import React, {Component} from 'react';
import {StyleSheet, View, Button} from 'react-native';
export default class raspberry extends Component {
constructor(props) {
super(props);
this.ws = new WebSocket('ws://127.0.0.1:8000/4f54b02b3f304e8097a087a5baee3c37');
this.ws.onopen = () => {
// connection opened
this.ws.send('something'); // send a message
};
this.ws.onmessage = (e) => {
// a message was received
console.log(e.data);
};
this.ws.onerror = (e) => {
// an error occurred
console.log(e.message);
};
this.ws.onclose = (e) => {
// connection closed
console.log(e.code, e.reason);
};
}
он возвращает это в журнале:
[Sat Jul 11 2020 24:01:33.780] LOG Failed to connect to /127.0.0.1:8000
[Sat Jul 11 2020 24:01:33.790] LOG undefined undefined
[Sat Jul 11 2020 24:01:33.790] LOG Failed to connect to /127.0.0.1:8000
[Sat Jul 11 2020 24:01:33.800] LOG undefined undefined
У меня есть сервер ржавчины, работающий по URL-адресу, который я передаю в веб-сокет , сервер работает нормально, я тестирую его с помощью команды websocat -t: websocat -t wss://127.0.0.1:8000/wss/4f54b02b3f304e8097a087a5baee3c37