i want to create server connection using socket.
i added the code but “Connection to the server failed.”
message come every time.how its resolved
try {
val mSocket = IO.socket(“http://52.38.229.70:5000”)
mSocket.on(Socket.EVENT_CONNECT, Emitter.Listener {
Log.d("SocketConnection", "Socket is connected to the server.")
}).on(Socket.EVENT_CONNECT_ERROR, Emitter.Listener {
Log.d("SocketConnection", "Connection to the server failed.")
})
mSocket.connect()
// Emit data to the server
val send_data = "1234"
mSocket.emit("eventName", send_data)
} catch (e: URISyntaxException) {
Log.e("SocketConnection", "URISyntaxException: ${e.message}")
} catch (e: Exception) {
Log.e("SocketConnection", "Error occurred: ${e.message}")
}