File tree Expand file tree Collapse file tree 9 files changed +135
-0
lines changed Expand file tree Collapse file tree 9 files changed +135
-0
lines changed Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <classpath >
3
+ <classpathentry kind =" src" path =" src" />
4
+ <classpathentry kind =" con" path =" org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.8" />
5
+ <classpathentry kind =" output" path =" bin" />
6
+ </classpath >
Original file line number Diff line number Diff line change
1
+ <?xml version =" 1.0" encoding =" UTF-8" ?>
2
+ <projectDescription >
3
+ <name >Networking</name >
4
+ <comment ></comment >
5
+ <projects >
6
+ </projects >
7
+ <buildSpec >
8
+ <buildCommand >
9
+ <name >org.eclipse.jdt.core.javabuilder</name >
10
+ <arguments >
11
+ </arguments >
12
+ </buildCommand >
13
+ </buildSpec >
14
+ <natures >
15
+ <nature >org.eclipse.jdt.core.javanature</nature >
16
+ </natures >
17
+ </projectDescription >
Original file line number Diff line number Diff line change
1
+ eclipse.preferences.version =1
2
+ org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode =enabled
3
+ org.eclipse.jdt.core.compiler.codegen.targetPlatform =1.8
4
+ org.eclipse.jdt.core.compiler.codegen.unusedLocal =preserve
5
+ org.eclipse.jdt.core.compiler.compliance =1.8
6
+ org.eclipse.jdt.core.compiler.debug.lineNumber =generate
7
+ org.eclipse.jdt.core.compiler.debug.localVariable =generate
8
+ org.eclipse.jdt.core.compiler.debug.sourceFile =generate
9
+ org.eclipse.jdt.core.compiler.problem.assertIdentifier =error
10
+ org.eclipse.jdt.core.compiler.problem.enumIdentifier =error
11
+ org.eclipse.jdt.core.compiler.source =1.8
Original file line number Diff line number Diff line change
1
+ package com .cdac .networking ;
2
+
3
+ import java .net .InetAddress ;
4
+ import java .net .MalformedURLException ;
5
+ import java .net .URL ;
6
+ import java .net .UnknownHostException ;
7
+
8
+ public class NetworkInfo {
9
+
10
+ public static void main (String [] args ) throws UnknownHostException , MalformedURLException {
11
+ InetAddress inetAddress = InetAddress .getByName ("google.com" );
12
+ System .out .println ("Host Name : " +inetAddress .getHostName ());
13
+ System .out .println ("Host Address : " +inetAddress .getHostAddress ());
14
+
15
+ inetAddress = InetAddress .getByName ("facebook.com" );
16
+ System .out .println ("Host Name : " +inetAddress .getHostName ());
17
+ System .out .println ("Host Address : " +inetAddress .getHostAddress ());
18
+
19
+ URL url = new URL ("http://localhost:8080/testApp" );
20
+ System .out .println ("Protocol : " +url .getProtocol ());
21
+ System .out .println ("Host : " +url .getHost ());
22
+ System .out .println ("Port No : " +url .getPort ());
23
+ System .out .println ("Path : " +url .getPath ());
24
+ System .out .println ("Default Port : " +url .getDefaultPort ());
25
+ System .out .println ("End of the Program" );
26
+ }
27
+ }
Original file line number Diff line number Diff line change
1
+ package com .cdac .networking ;
2
+
3
+ import java .io .DataInputStream ;
4
+ import java .io .DataOutputStream ;
5
+ import java .io .IOException ;
6
+ import java .net .Socket ;
7
+ import java .net .UnknownHostException ;
8
+ import java .util .Scanner ;
9
+
10
+ public class TCPClient {
11
+
12
+ public static void main (String [] args ) throws UnknownHostException , IOException {
13
+ Scanner scanner = new Scanner (System .in );
14
+ String ipAddress = "localhost" ;
15
+ int portNumbe = 5500 ;
16
+ Socket socket = new Socket (ipAddress , portNumbe );
17
+
18
+ DataInputStream dis = new DataInputStream (socket .getInputStream ());
19
+ DataOutputStream dos = new DataOutputStream (socket .getOutputStream ());
20
+
21
+ String line = "" ;
22
+ while ( !line .equals ( "Stop" ))
23
+ {
24
+ System .out .println ("Send msg to Server :: " );
25
+ line = scanner .nextLine ();
26
+ dos .writeUTF (line );
27
+ String strFromServer = dis .readUTF ();
28
+ System .out .println ("Server says :: " +strFromServer );
29
+ }
30
+
31
+ dis .close ();
32
+ dos .close ();
33
+ socket .close ();
34
+ }
35
+ }
Original file line number Diff line number Diff line change
1
+ package com .cdac .networking ;
2
+
3
+ import java .io .DataInputStream ;
4
+ import java .io .DataOutputStream ;
5
+ import java .io .IOException ;
6
+ import java .net .ServerSocket ;
7
+ import java .net .Socket ;
8
+ import java .util .Scanner ;
9
+
10
+ public class TCPServer {
11
+
12
+ public static void main (String [] args ) throws IOException {
13
+ Scanner scanner = new Scanner (System .in );
14
+ int portNumber = 5500 ;
15
+
16
+ ServerSocket server = new ServerSocket (portNumber );
17
+ System .out .println ("Server is waiting for the client." );
18
+ Socket socket = server .accept ();
19
+ System .out .println ("Client is connected." );
20
+
21
+ DataInputStream dis = new DataInputStream (socket .getInputStream ());
22
+ DataOutputStream dos = new DataOutputStream (socket .getOutputStream ());
23
+
24
+ String line = "" ;
25
+ while ( !line .equals ( "Stop" ))
26
+ {
27
+ String strFromClient = dis .readUTF ();
28
+ System .out .println ("Client Says :: " +strFromClient );
29
+ System .out .println ("Enter Server Reply :: " );
30
+ line = scanner .nextLine ();
31
+ dos .writeUTF (line );
32
+ }
33
+
34
+ dis .close ();
35
+ dos .close ();
36
+ server .close ();
37
+ socket .close ();
38
+ }
39
+ }
You can’t perform that action at this time.
0 commit comments