Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 95e5f57

Browse files
some changes
1 parent 9e830bf commit 95e5f57

File tree

7 files changed

+63
-90
lines changed

7 files changed

+63
-90
lines changed

‎.idea/workspace.xml

Lines changed: 47 additions & 86 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎src/com/example/hello_world_package/Network_Programming_TCP_Client_Code.java

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,12 @@ public class Network_Programming_TCP_Client_Code {
1111

1212

1313
public static void main(String[] args) throws IOException {
14-
Socket socket = new Socket("127.0.0.1",1500);
14+
Socket socket = new Socket("127.0.0.1",1500);//first argument is server's IP address
15+
// second argument is port number of the server to which our client program will send the client request depending upon the application level protocol
16+
// it is 80 for HTTP protocol and we are using HTTP here
17+
//but lets use a different port here, 1500
18+
19+
1520

1621
//Lets send a number to the server, double it there and then get that value back to the client and print here
1722
int to_send_to_Server, to_receive_from_the_server;

‎src/com/example/hello_world_package/Network_Programming_TCP_Server_Code.java

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,17 @@
88

99
public class Network_Programming_TCP_Server_Code {
1010
public static void main(String[] args) throws IOException {
11-
ServerSocket serverSocket = new ServerSocket(1500);
12-
Socketsocket = serverSocket.accept();
11+
ServerSocket serverSocket = new ServerSocket(1500);//this port number 1500 is where this server socket will listen to for
12+
//any incoming requests
1313

14-
//lets set an inputstream for this socket
14+
Socket socket = serverSocket.accept(); //Listens for a connection to be made to this socket and accepts it.
15+
//lets see the port number of the client where this server connects to
16+
System.out.println("\n The port number used for client is "+socket.getPort());//Returns the client machine's port number to which this socket is connected.
17+
18+
//You might think how does the server know which port to connect to on the client
19+
//Client's port number is the part of the TCP header in the ip packet. So the server finds out because the client tells it through its TCP header.
20+
21+
// lets set an inputstream for this socket
1522
Scanner scanner = new Scanner(socket.getInputStream());
1623
int input_from_the_client = scanner.nextInt();
1724

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /