Search
Search titles only
By:
Search titles only
By:
Log in
Register
Search
Search titles only
By:
Search titles only
By:
Menu
Install the app
Install
Forums
New posts
All threads
Latest threads
New posts
Trending threads
Trending
Search forums
What's new
New posts
New ads
New profile posts
Latest activity
Free Ads
Latest reviews
Search ads
Members
Current visitors
New profile posts
Search profile posts
Contact us
Latest ads
Puffin Rock Characters Plush Toy Set
anil1961
Updated:
Saturday at 3:51 PM
Toyota Vitz scp10 For Sale
Lakmal Bandara
Updated:
Wednesday at 10:50 AM
Kandy
Welcome all my all new pet shop Bark.lk
dilumrane
Updated:
Nov 2, 2026
Windows RDP Only Rs.500 a month
Blogerwiki
Updated:
Nov 1, 2026
Ad icon
V2ray VPN for Tunneling
hu KANNA
Updated:
Oct 22, 2026
Electronics
Vehicles
Property
Search
Reply to thread
Forums
General
ElaKiri Talk!
UDP Socket Programming in Java
Get the App
JavaScript is disabled. For a better experience, please enable JavaScript in your browser before proceeding.
You are using an out of date browser. It may not display this or other websites correctly.
You should upgrade or use an
alternative browser
.
Message
<blockquote data-quote="MihiCherub" data-source="post: 17162228" data-attributes="member: 238676"><p><span style="font-size: 12px">අඩෝ කියල දෙන්න දන්නෙ නෑ බන්.. ඒ කිව්වෙ මේව වැඩිය මම පාවිච්චි කරල නෑ.. <img src="/styles/default/xenforo/smilies/default/sorry.gif" class="smilie" loading="lazy" alt=":sorry:" title="Sorry :sorry:" data-shortname=":sorry:" /></span></p><p></p><p>[CODE] public static boolean isConnectionAvailable() {</p><p> Socket socket = new Socket();</p><p> InetSocketAddress address = new InetSocketAddress("www.google.com", 80);</p><p> try {</p><p> socket.connect(address, 3000);</p><p> return true;</p><p> } catch (IOException ex) {</p><p> System.out.println("Connection failed. java.net.UnknownHost: www.google.com");</p><p> } finally {</p><p> try {</p><p> socket.close();</p><p> } catch (Exception ex) {</p><p> Logger.getLogger(InternetConnection.class.getName()).log(Level.SEVERE, null, ex);</p><p> }</p><p> }</p><p> return false;</p><p> }[/CODE]</p><p></p><p><span style="font-size: 12px">පලවෙනි කෝඩ් එකෙන් කරන්නෙ පින්ග් කරල බලනව internet connection එක තියෙනවද කියල. අපි මෙහෙම හිතමු. උබට ඕනෙ backup එකක් upload කරන්න. එතකොට internet connection එක තියෙනවද කියල මේ ක්රමේට බලන්න පුලුවන්. බොහොම සරල ක්රමයක්.. google කියන්නෙ ලේසියෙන් වැටෙන්නෙ නැති සයිට් එකක් නෙ.</span></p><p></p><p>[CODE] public static String getHostIP(String host) {</p><p> try {</p><p> return InetAddress.getByName(host).getHostAddress();</p><p> } catch (UnknownHostException ex) {</p><p> Logger.getLogger(InternetConnection.class.getName()).log(Level.SEVERE, null, ex);</p><p> }</p><p> return null;</p><p> }[/CODE]</p><p></p><p><span style="font-size: 12px">ඊට පස්සෙ අපිට ඕනෙ නම් මේකෙන් IP address ගන්න පුලුවන්. එතකොට එන්නෙ මුලින්ම return කරන IP එක. නමුත් google, fb වගේ සයිට් වලට IP ගොඩක් තියෙනව. මේ ඔක්කොම ගන්න ඕනෙ නම් යට කෝඩ් එකෙන් පුලුවන්.</span></p><p></p><p>[CODE] public static InetAddress[] getAllHostIP(String host) {</p><p> try {</p><p> return InetAddress.getAllByName(host);</p><p> } catch (UnknownHostException ex) {</p><p> Logger.getLogger(InternetConnection.class.getName()).log(Level.SEVERE, null, ex);</p><p> }</p><p> return null;</p><p> }[/CODE]</p></blockquote><p></p>
[QUOTE="MihiCherub, post: 17162228, member: 238676"] [SIZE=3]අඩෝ කියල දෙන්න දන්නෙ නෑ බන්.. ඒ කිව්වෙ මේව වැඩිය මම පාවිච්චි කරල නෑ.. :sorry:[/SIZE] [CODE] public static boolean isConnectionAvailable() { Socket socket = new Socket(); InetSocketAddress address = new InetSocketAddress("www.google.com", 80); try { socket.connect(address, 3000); return true; } catch (IOException ex) { System.out.println("Connection failed. java.net.UnknownHost: www.google.com"); } finally { try { socket.close(); } catch (Exception ex) { Logger.getLogger(InternetConnection.class.getName()).log(Level.SEVERE, null, ex); } } return false; }[/CODE] [SIZE=3]පලවෙනි කෝඩ් එකෙන් කරන්නෙ පින්ග් කරල බලනව internet connection එක තියෙනවද කියල. අපි මෙහෙම හිතමු. උබට ඕනෙ backup එකක් upload කරන්න. එතකොට internet connection එක තියෙනවද කියල මේ ක්රමේට බලන්න පුලුවන්. බොහොම සරල ක්රමයක්.. google කියන්නෙ ලේසියෙන් වැටෙන්නෙ නැති සයිට් එකක් නෙ.[/SIZE] [CODE] public static String getHostIP(String host) { try { return InetAddress.getByName(host).getHostAddress(); } catch (UnknownHostException ex) { Logger.getLogger(InternetConnection.class.getName()).log(Level.SEVERE, null, ex); } return null; }[/CODE] [SIZE=3]ඊට පස්සෙ අපිට ඕනෙ නම් මේකෙන් IP address ගන්න පුලුවන්. එතකොට එන්නෙ මුලින්ම return කරන IP එක. නමුත් google, fb වගේ සයිට් වලට IP ගොඩක් තියෙනව. මේ ඔක්කොම ගන්න ඕනෙ නම් යට කෝඩ් එකෙන් පුලුවන්.[/SIZE] [CODE] public static InetAddress[] getAllHostIP(String host) { try { return InetAddress.getAllByName(host); } catch (UnknownHostException ex) { Logger.getLogger(InternetConnection.class.getName()).log(Level.SEVERE, null, ex); } return null; }[/CODE] [/QUOTE]
Insert quotes…
Verification
Hath warak paha keeyada? (hatha wadikireema paha)
Post reply
Top
Bottom