https://kotlinlang.org logo
a

Aditya Verma

07/06/2023, 9:45 AM
I'm working on a Koltin multiplatform project targeting android and desktop (windows). For desktop module how can I connect to a socket.io server running on an express application deployed on cloud? Any working solutions would be highly appreciated. I've tried okhttp, ktor websockets and socket.io client but none seem to work for desktop. Stuck on it for two days now. Any help would be appreciated. This is my Index.js file for socket.io integrated express application-
Copy code
const app = require('express')();
const http = require('http').Server(app);
const io = require('<http://socket.io|socket.io>')(http, {
    cors: {
      origin: '*',
    }
});
const port = process.env.PORT || 3000;

io.on('connection', (socket) => {
  console.log('user connected to socket')
  
  socket.on('chat message', msg => {
    io.emit('chat message', msg);
  });

});

http.listen(port, () => {
  console.log(`<http://Socket.IO|Socket.IO> server running at <http://localhost>:${port}/`);
});