0% found this document useful (0 votes)
1 views

Network programming lab report

The document provides a series of Java programming tasks focused on socket programming, including creating echo applications, client-server communication, and handling UDP connections. It includes example code for an echo server and client, as well as a chat server and client. Additional tasks involve URL handling, HTTP connections, and RMI applications for various functionalities.

Uploaded by

ABDUL HALEEM
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
1 views

Network programming lab report

The document provides a series of Java programming tasks focused on socket programming, including creating echo applications, client-server communication, and handling UDP connections. It includes example code for an echo server and client, as well as a chat server and client. Additional tasks involve URL handling, HTTP connections, and RMI applications for various functionalities.

Uploaded by

ABDUL HALEEM
Copyright
© © All Rights Reserved
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 4

1. Write a program for Java echo Application using socket programming.

2. Write a client-side program to read an information from server using socket.


3. Write a program to perform a basic text messaging between client and server.
4. Write down a program for finding a factorial using socket programming.
5. Write a program to find IP address of any hostname.
6. Write a program to constructing a URL.
7. Write a program to show the parts of the URL (Splitting URL).
8. Write a program to download a webpage using URL Connection.
9. Write a program to demonstrate the use of Http URL Connection.
10. Write a program to demonstrate URI Class.
11. Write a program for URL Encoder and Decoder.
12. Write a program to demonstrate the x-www-form-url encoded strings.
13. A cookie policy that blocks all .gov cookies but allow others.
14. Write a Program to read data from URL or reading data from server
15. Write a program to print the URL of a URL Connection to “tufohss.edu.np”.
16. Write a program to read value of HTTP Header fields.
17. Write a program to print the entire HTTP Header.
18. Write a program to read URL Contents by Response code using HttpURLConnection.
19. Write a client-side program to read an information from server using socket.
20. Write multithreaded TCP client and server socket programs for daytime service.
21. Write a program for Creating Secure Sockets with tufohss.edu.np
22. Write UDP Client and server socket programs in which the server identifies the number sent by a client is either
even or odd and replies to client accordingly.
23. Write a program to create a simple UDP client.
24. Write a program for UDP client and UDP Server to find the factorial of the entered number.
25. Write a client server-based program using UDP to find the factorial of the entered number.
26. Write a program to join a computer system in a multicast group.
27. Program to verify that you are receiving multicast data at a particular host.
28. Write a program to add and subtract two numbers using RMI.
29. Write a program to find factorial numbers using RMI.
30. Write a RMI Client and server program to find greater number among two numbers.
31. Write a program to develop a multithreaded chat application between client and server.
1. Write a program for Java echo Application using socket programming

// EchoServer.java
import java.io.*;
import java.net.*;

public class EchoServer {


public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(5000);
System.out.println("Server started. Waiting for client...");

Socket socket = serverSocket.accept();


System.out.println("Client connected.");

BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));


PrintWriter output = new PrintWriter(socket.getOutputStream(), true);

String received;
while ((received = input.readLine()) != null) {
System.out.println("Received from client: " + received);
output.println("Echo: " + received);
}

socket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

// EchoClient.java
import java.io.*;
import java.net.*;

public class EchoClient {


public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 5000);

BufferedReader input = new BufferedReader(new InputStreamReader(socket.getInputStream()));


PrintWriter output = new PrintWriter(socket.getOutputStream(), true);
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

String message;
System.out.println("Type messages to send to server. Type 'exit' to quit.");

while (true) {
System.out.print("You: ");
message = console.readLine();
if (message.equalsIgnoreCase("exit")) break;

output.println(message);
String reply = input.readLine();
System.out.println("Server: " + reply);
}

socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

2. Write a client-side program to read an information from server using socket.

//ChatServer.java

import java.io.*;
import java.net.*;

public class ChatServer {


public static void main(String[] args) {
try {
ServerSocket serverSocket = new ServerSocket(6000);
System.out.println("Chat server started...");

Socket socket = serverSocket.accept();


System.out.println("Client connected.");

BufferedReader in = new BufferedReader(new


InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

String msg;
while (true) {
msg = in.readLine();
if (msg.equalsIgnoreCase("bye")) break;
System.out.println("Client: " + msg);

System.out.print("You: ");
String reply = console.readLine();
out.println(reply);
}

socket.close();
serverSocket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}
//ChatClient.java
import java.io.*;
import java.net.*;

public class ChatClient {


public static void main(String[] args) {
try {
Socket socket = new Socket("localhost", 6000);
System.out.println("Connected to server.");

BufferedReader in = new BufferedReader(new


InputStreamReader(socket.getInputStream()));
PrintWriter out = new PrintWriter(socket.getOutputStream(), true);
BufferedReader console = new BufferedReader(new InputStreamReader(System.in));

String msg;
while (true) {
System.out.print("You: ");
String message = console.readLine();
out.println(message);
if (message.equalsIgnoreCase("bye")) break;

msg = in.readLine();
System.out.println("Server: " + msg);
}

socket.close();
} catch (IOException e) {
e.printStackTrace();
}
}
}

You might also like