How to Implement real-time chatting using node.js and Socket.io in react-native?

Viewed 3192

I am looking for resources to guide me across server-side (Mostly) and client-side. I have referred this resource Simple Real Time chat app. But I am not getting significant results.

I locally hosted this server-side script index.js with port number 3000. I ran this script using node index.js.Parallelly, I ran the react-native code (Android Platform) and made sure that socket.io listens the port number 3000. But when i do any sought of communication from the server side or client side, i am not getting any results.

3 Answers

I read the code and I can't say what exactly is the problem but I will give some advice

in server code user createServer method instead of server in

var server = http.Server(app);

in client code try to defer(stall) the use of any method on the socket for the next tick in the event loop using a fake non-sense setTimeout like

....new Socket

....setTimeout(() => { ...socket.emit }, 0)

because this will garantes the socket is well connected and you didn't use the emit on non-ready socket

I've tried using socket.IO once in react-native it works great back then.I wonder what could possible go wrong in your case!

try at least with a smaller example app then find out if there is any problem with this one.

and a piece of advice..check Rocket.chat and if you find it suitable I can help you with building the client cheerfully

Related