Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 206
Ron Astle Lobo Avatar asked Oct 25 '18 13:10

Ron Astle Lobo


2 Answers

Let me know if these links are will help as resources:

  • Simple Chat App
  • The GitHub to the above mentioned Chat App
  • React Native Chat App
  • Node.JS Websocket Chat App
  • Android, NodeJs, and Socket.io ChatApp
like image 191
B. Cratty Avatar answered Sep 23 '22 12:09

B. Cratty


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

like image 24
Mhd Louay Al-osh Avatar answered Sep 20 '22 12:09

Mhd Louay Al-osh