Below is my react native component that I am trying to connect to my node websocket backend.
import React from 'react';
import { StyleSheet, Text, View, Image } from 'react-native';
import io from 'socket.io-client';
let socket = io('ws://localhost:3000');
export default class App extends React.Component {
constructor(props) {
super(props);
console.log(socket);
}
render() {
return (
<View>
<Text>Websocket</Text>
</View>
);
}
}
Here is my node server.js code. Can anyone see what I am doing wrong here and why I cannot connect my react app to my node server?
const express = require('express');
const http = require('http')
const socketio = require('socket.io');
const app = express();
const server = http.Server(app);
const websocket = socketio(server);
server.listen(3000, () => console.log('listening on *:3000'));
console.log(websocket)
// The event will be called when a client is connected.
websocket.on('connection', (socket) => {
console.log('A client just joined on', socket.id);
});
via peter flanagan
No comments:
Post a Comment