Check out example codes for "socket.io kotlin". It will help you in understanding the concepts better.

Code Example 1

//kotlin
import com.github.nkzawa.emitter.Emitter
import com.github.nkzawa.socketio.client.IO
import com.github.nkzawa.socketio.client.Socket

val socket = IO.socket("http://localhost:4000/")

socket.on(Socket.EVENT_CONNECT, Emitter.Listener {
    socket.emit("messages", "hi")
});

Learn ReactJs, React Native from akashmittal.com