I am using socket.io in Android as client and connects to node.js server. I follows the guide in socket.io ([https://socket.io/blog/native-socket-io-and-android/]) as in the following:
import io.socket.client.IO;
import io.socket.client.Socket;
private Socket mSocket;
{
try {
mSocket = IO.socket("http://chat.socket.io");
} catch (URISyntaxException e) {}
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
mSocket.connect();
}
and the server side is launched by node.js.
const express = require('express');
const app = express();
const http = require('http');
const server = http.createServer(app);
const { Server } = require("socket.io");
const io = new Server(server);
app.get('/', (req, res) => {
res.sendFile(__dirname + '/index.html');
});
io.on('connection', (socket) => {
console.log('a user connected');
});
server.listen(3000, () => {
console.log('listening on *:3000');
});
But when the connection is made the emission does not trigger. That means the message ‘a user connected’ does not show.
Do anyone knows what happens?
Thank you for any help!