File tree 1 file changed +25
-0
lines changed
1 file changed +25
-0
lines changed Original file line number Diff line number Diff line change
1
+ import java .net .InetAddress ;
2
+ import java .net .Socket ;
3
+ import java .net .SocketException ;
4
+ import java .net .UnknownHostException ;
5
+ import java .io .IOException ;
6
+
7
+ public class SocketToPort {
8
+ public static void main (String [] args ) {
9
+ try {
10
+ InetAddress address = InetAddress .getByName ("179.105.231.48" );
11
+ Socket socket = new Socket (address , 80 );
12
+ System .out .println ("Established connection to "
13
+ + socket .getInetAddress ()
14
+ + " on port #" + socket .getPort () + " from port #"
15
+ + socket .getLocalPort () + " of device IP "
16
+ + socket .getLocalAddress ());
17
+ } catch (UnknownHostException e ) {
18
+ System .err .println ("Cannot find host: " + e );
19
+ } catch (SocketException e ) {
20
+ System .err .println ("Cannot establish connection: " +e );
21
+ } catch (IOException e ) {
22
+ System .err .println (e );
23
+ }
24
+ }
25
+ }
You can’t perform that action at this time.
0 commit comments