0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

Androidでのネット疎通確認

Posted at

はじめに

今回はAndroid端末でネット疎通確認をするためのコードを紹介していこうと思います

本文

withContext(ioDispatcher) {
            resultOf {
            // hostnameには適当なアドレスをいれておきます
                val inetHostname = InetAddress.getByName(hostname)
                val inetSocketAddress = InetSocketAddress(inetHostname, HTTPS_PORT)

                Socket().use { it.connect(inetSocketAddress, TIMEOUT_MILLIS) }
            }
        }

こうすることでネットが正常に疎通しているかを確認することができます

さいごに

今回はネット疎通確認用のコードを紹介しました
どなたかのお役に立てれば幸いです

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?