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
Ad icon
ZTE MF283U 4G Unlocked Router (Used)
ayanthamaxi
Updated:
Yesterday at 8:26 PM
ලංකාවේ හොඳම උපකාරක පන්ති සහ ගුරුවරුන් එකම තැනකින් - TopTuition.lk
dulithapathum
Updated:
Saturday at 8:07 AM
Colombo
RidhMathraa ’26 🎶✨
Tmadhusanka
Updated:
Wednesday at 11:58 PM
Ad icon
Colombo
PXN V10 Pro Direct Drive Racing Wheel (Under Warranty)
Abdur Rahman
Updated:
Wednesday at 10:23 PM
Ad icon
USDT ණය සේවාව - USDT Loan Service
පුරවැසියා
Updated:
Wednesday at 4:54 PM
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
Hathara warak wissa keeyada? (Hathara wadi karanna 20)
Post reply
Top
Bottom