-
-
Notifications
You must be signed in to change notification settings - Fork 508
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
What I'm doing wrong (with react native) #244
Comments
It looks like it is phpsocket.io not compatible with your react native socket.io client. |
My application is build in PHP, Flutter and React Native. We are actually moving to React Native from Flutter and we can't get get the React Native app to connect to the Socket Server so we came up with a solution to use SwoolePHP or Node.js socket.io then call our PHP apis from the Node.js Server when required. |
Another thing you can do to fix things would be to install an older version of socket.io-client maybe Go to the |
Hi,
I'm using RN with phpsocket.io.
I can connect to socket but any emit works.
What I'm doing wrong ?
Here is my RN code :
<?php require_once __DIR__ . '/man/Autoloader.php'; require_once __DIR__ . '/io/src/autoload.php'; use Workerman\Worker; use PHPSocketIO\SocketIO; $io = new SocketIO(20200); $io -> on('connection', function($socket) { echo "connected\n"; $socket -> on('message', function($data) use($socket) { echo "new message reveived !\n"; $socket -> broadcast -> emit('new message', 'ello'); }); }); Worker::runAll(); ?>
So, on the server side, I always see "connected" in log console.
In React Native, on mount component, I write this :
componentDidMount() { this.socket = io('http://my_dns:20200') this.socket.on("new message", msg => { console.log('new message : '+msg) }) }
If I understand, I'm listening to emit event from server, when user send new message, I write it in console.
And I have a fake button, which send a fake message to server :
this.socket.emit("message", 'hello word')
But the event never received by my server, I never see in console "new message recevied"
I really spend lot of hours to understand what is the mistake.
Can anybody helps me please ?
Thanks a lot
The text was updated successfully, but these errors were encountered: