[英]native android not connecting to socket.io
I am trying to connect my server deployed in heroko.我正在尝试连接部署在 heroko 中的服务器。 But as you can see in the code below, i can't connect to my server.
但正如您在下面的代码中看到的,我无法连接到我的服务器。 I tried it in web (with just html,javascript) and i am able to connect.
我在 web 中尝试过(仅使用 html,javascript),我能够连接。
But in android using kotlin, i can't connect.但是在使用 kotlin 的 android 中,我无法连接。 I tried adding android:usesCleartextTraffic but doesn't work.
我尝试添加 android:usesCleartextTraffic 但不起作用。 Did anyone faced this issue?
有人遇到过这个问题吗?
class MainActivity : AppCompatActivity() {
private val TAG = "mytag"
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_main)
val socket = IO.socket("https://nesib-api.herokuapp.com/")
socket.connect()
Log.d(TAG, "socked connected : "+ socket.connected()) // always returns false
socket.on(Socket.EVENT_CONNECT){
Log.d(TAG, "connected ! ") // this method never fires
}
}
} }
Write <uses-permission android:name="android.permission.INTERNET" />
in your AndroidManifest.xml .在您的AndroidManifest.xml中写入
<uses-permission android:name="android.permission.INTERNET" />
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.