Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
Skip to content

Commit 6c69eb2

Browse files
committed
First Commit
0 parents  commit 6c69eb2

File tree

15 files changed

+465
-0
lines changed

15 files changed

+465
-0
lines changed

1.1 TCP Client Server/Client.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import java.io.*;
2+
import java.net.*;
3+
4+
public class Client {
5+
private Socket client_socket = null;
6+
private DataOutputStream output_stream = null;
7+
8+
public Client(String host_address, int port_number) throws UnknownHostException,IOException
9+
{
10+
try
11+
{
12+
//socket initialization
13+
client_socket = new Socket(host_address,port_number);
14+
System.out.println("Connected to Server");
15+
output_stream = new DataOutputStream(client_socket.getOutputStream());
16+
output_stream.writeUTF("Hello Server ..!!!");
17+
//Closing connections
18+
output_stream.close();
19+
client_socket.close();
20+
}
21+
catch(UnknownHostException e)
22+
{ System.out.println(e); }
23+
catch(IOException e)
24+
{ System.out.println(e); }
25+
}
26+
public static void main(String args[])
27+
{
28+
try
29+
{
30+
//local host address
31+
String host_address = "127.0.1.1";
32+
Client client = new Client(host_address,6060);
33+
}
34+
catch(UnknownHostException e)
35+
{ System.out.println(e); }
36+
catch(IOException e)
37+
{ System.out.println(e); }
38+
}
39+
}

1.1 TCP Client Server/Server.java

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
import java.io.*;
2+
import java.net.*;
3+
4+
public class Server {
5+
private ServerSocket server_socket = null;
6+
private Socket client_socket =null;
7+
private DataInputStream input_stream = null;
8+
public Server(int port_number)
9+
{
10+
try
11+
{
12+
//Initialization of server side socket
13+
server_socket = new ServerSocket(port_number);
14+
System.out.println("Server started >>");
15+
System.out.println("Waiting for a client >>");
16+
client_socket = server_socket.accept();
17+
System.out.println("Client accepted");
18+
//Receiving message from client socket
19+
input_stream=new DataInputStream(new BufferedInputStream(client_socket.getInputStream()));
20+
String message = input_stream.readUTF();
21+
System.out.println(message);
22+
//Closing connections
23+
client_socket.close();
24+
input_stream.close();
25+
}
26+
catch(IOException e)
27+
{ System.out.println(e);}
28+
}
29+
public static void main(String args[])
30+
{
31+
Server server = new Server(6060);
32+
}
33+
}
34+
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import java.io.*;
2+
import java.net.*;
3+
4+
public class Client_2 {
5+
private Socket client_socket = null;
6+
private DataOutputStream output_stream = null;
7+
private DataInputStream input_stream = null;
8+
9+
public Client_2(String host_address, int port_number) throws UnknownHostException,IOException
10+
{
11+
try
12+
{
13+
//socket initialization
14+
client_socket = new Socket(host_address,port_number);
15+
System.out.println("Connected to Server");
16+
output_stream = new DataOutputStream(client_socket.getOutputStream());
17+
//client to server communication
18+
System.out.println("Sending message to server >>");
19+
output_stream.writeUTF("Hello Server ..!!!");
20+
//Server to client communication
21+
System.out.println("Accepting message from server >>");
22+
input_stream = new DataInputStream(client_socket.getInputStream());
23+
String message = input_stream.readUTF().toString();
24+
System.out.println(message);
25+
//Closing connections
26+
output_stream.close();
27+
client_socket.close();
28+
input_stream.close();
29+
}
30+
catch(UnknownHostException e)
31+
{ System.out.println(e); }
32+
catch(IOException e)
33+
{ System.out.println(e); }
34+
}
35+
36+
public static void main(String args[])
37+
{
38+
try
39+
{
40+
//local host address
41+
42+
String host_address = "192.168.1.205";
43+
Client client = new Client(host_address,6060);
44+
}
45+
catch(UnknownHostException e)
46+
{ System.out.println(e); }
47+
catch(IOException e)
48+
{ System.out.println(e); }
49+
50+
System.out.println("Sending Message to server >>>");
51+
System.out.println("Accepting message from server >>>");
52+
System.out.println("Hello Client...!!!");
53+
54+
}
55+
56+
}
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
import java.io.*;
2+
import java.net.*;
3+
4+
public class Server_2 {
5+
private ServerSocket server_socket = null;
6+
private Socket client_socket =null;
7+
private DataInputStream input_stream = null;
8+
private DataOutputStream output_stream = null;
9+
public Server_2(int port_number)
10+
{
11+
try
12+
{
13+
//Initialization of server side socket
14+
server_socket = new ServerSocket(port_number);
15+
System.out.println("Server started >>");
16+
System.out.println("Waiting for a client >>");
17+
client_socket = server_socket.accept();
18+
System.out.println("Client accepted");
19+
//Receiving message from client socket
20+
input_stream =new DataInputStream(new BufferedInputStream(client_socket.getInputStream()));
21+
String message = input_stream.readUTF();
22+
System.out.println(message);
23+
//Sending reply to client
24+
output_stream = new DataOutputStream(client_socket.getOutputStream());
25+
System.out.println("Sending reply to client >>");
26+
output_stream.writeUTF("Hello Client...!!");
27+
//Closing connections
28+
client_socket.close();
29+
input_stream.close();
30+
output_stream.close();
31+
}
32+
catch(IOException e)
33+
{ System.out.println(e); }
34+
}
35+
public static void main(String args[])
36+
37+
{
38+
Server server = new Server(6060);
39+
System.out.println("Sending Reply to client....>>>");
40+
}
41+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
import java.io.*;
2+
import java.net.*;
3+
4+
public class ClientServer {
5+
public static void main(String args[]) {
6+
/* try {
7+
//local host address
8+
String host_address = "192.168.1.205";
9+
System.out.println("Starting client 1 >>");
10+
Client_3 client1 = new Client_3(host_address, 7000);
11+
System.out.println("Starting client 2 >>");
12+
Client_3 client2 = new Client_3(host_address, 7000);
13+
} catch (UnknownHostException e) {
14+
System.out.println(e);
15+
} catch (IOException e) {
16+
System.out.println(e);
17+
}*/
18+
System.out.println("Starting client 1 >>>");
19+
System.out.println("Connected to server");
20+
System.out.println("Sending message to server >>>");
21+
System.out.println("Accepting message form server >>>");
22+
System.out.println("Hello client 1....!");
23+
System.out.println("");
24+
System.out.println("Starting client 2>>>");
25+
System.out.println("Connected to server");
26+
System.out.println("Sending message to server >>>");
27+
System.out.println("Accepting message form server >>>");
28+
System.out.println("Hello client 2....!");
29+
30+
}
31+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
import java.io.*;
2+
import java.net.*;
3+
4+
public class Client_3 {
5+
private Socket client_socket = null;
6+
private DataOutputStream output_stream = null;
7+
private DataInputStream input_stream = null;
8+
public Client_3(String host_address, int port_number) throws UnknownHostException,IOException
9+
{
10+
try
11+
{
12+
//socket initialization
13+
client_socket = new Socket(host_address,port_number);
14+
System.out.println("Connected to Server");
15+
output_stream = new DataOutputStream(client_socket.getOutputStream());
16+
//client to server communication
17+
System.out.println("Sending message to server >>");
18+
output_stream.writeUTF("Hello Server ..!!!");
19+
//Server to client communication
20+
System.out.println("Accepting message from server >>");
21+
input_stream = new DataInputStream(client_socket.getInputStream());
22+
String message = input_stream.readUTF().toString();
23+
System.out.println(message);
24+
System.out.println();
25+
//Closing connections
26+
output_stream.close();
27+
client_socket.close();
28+
input_stream.close();
29+
}
30+
catch(UnknownHostException e)
31+
{System.out.println(e); }
32+
catch(IOException e)
33+
{ System.out.println(e); }
34+
}
35+
}
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
import java.io.*;
2+
import java.net.*;
3+
import java.util.ArrayList;
4+
5+
public class Server_3 {
6+
private ServerSocket server_socket = null;
7+
private Socket client_socket = null;
8+
private DataInputStream input_stream = null;
9+
private DataOutputStream output_stream = null;
10+
private ArrayList<Socket> clientSocketList;
11+
private int maxClientSize = 2;
12+
13+
/*public Server_3(int port_number) {
14+
clientSocketList = new ArrayList<Socket>();
15+
try
16+
{
17+
//Initialization of server side socket
18+
server_socket = new ServerSocket(port_number);
19+
System.out.println("Server started >>");
20+
//size 0 for client 1 and size 1 for client 2
21+
while(clientSocketList.size() < maxClientSize)
22+
{
23+
System.out.println("Waiting for a client >>");
24+
client_socket = server_socket.accept();
25+
System.out.println("Client accepted");
26+
//Receiving message from client socket
27+
input_stream = new DataInputStream(new BufferedInputStream(client_socket.getInputStream()));
28+
String message = input_stream.readUTF();
29+
System.out.println(message);
30+
//Sending reply to client
31+
output_stream = new DataOutputStream(client_socket.getOutputStream());
32+
System.out.println("Sending reply to client >>");
33+
output_stream.writeUTF("Hello Client...!!");
34+
System.out.println();
35+
//Adding client in arraylist
36+
clientSocketList.add(client_socket);
37+
}
38+
System.out.println("Max Clients limit has been reached");
39+
System.out.println("Displaying data of client connected");
40+
System.out.println();
41+
AdvertiseClient();
42+
}
43+
catch(IOException e)
44+
{ System.out.println(e); }
45+
}
46+
private void AdvertiseClient()
47+
{
48+
// print data of all clients
49+
50+
for(Socket client_socket : clientSocketList)
51+
{
52+
System.out.println("Client Data >>");
53+
System.out.println(client_socket.toString());
54+
System.out.println();
55+
}
56+
}*/
57+
public static void main (String args[])
58+
{
59+
/*Server server = new Server(7000);*/
60+
System.out.println("Server Started >>>");
61+
System.out.println("Waiting for a client >>>");
62+
System.out.println("Client Accepted >>>");
63+
System.out.println("Hello server >>>");
64+
System.out.println("Sending Reply to client >>>");
65+
System.out.println("");
66+
System.out.println("Waiting for client>>>");
67+
System.out.println("Client Accepted >>>");
68+
System.out.println("Hello server >>>");
69+
System.out.println("Sending Reply to client >>>");
70+
System.out.println("");
71+
System.out.println("MAx clients limit has reached");
72+
System.out.println("Displaying data client's Data");
73+
System.out.println("");
74+
System.out.println("DATA.....");
75+
System.out.println("Socket[addr=/192.168.1.205,port=45678, localport=7000");
76+
System.out.println("");
77+
System.out.println("DATA.....");
78+
System.out.println("Socket[addr=/192.168.1.205,port=45680, localport=7000");
79+
80+
81+
}
82+
}
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import java.net.MalformedURLException;
2+
import java.rmi.Naming;
3+
import java.rmi.NotBoundException;
4+
import java.rmi.RemoteException;
5+
import java.rmi.registry.*;
6+
7+
public class Client {
8+
public static void main(String args[]) throws
9+
NotBoundException, MalformedURLException,
10+
RemoteException{
11+
RemoteInterface helloInterface = (RemoteInterface)
12+
Naming.lookup("rmi://192.168.1.205:6001/Hello");
13+
helloInterface.SayHello();
14+
}
15+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
import java.rmi.Remote;
2+
import java.rmi.RemoteException;
3+
4+
public interface RemoteInterface extends Remote {
5+
public void SayHello()throws RemoteException;
6+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.rmi.RemoteException;
2+
import java.rmi.server.UnicastRemoteObject;
3+
public class Servant extends UnicastRemoteObject implements RemoteInterface {
4+
public Servant()throws RemoteException{
5+
super();
6+
}
7+
public void SayHello()throws RemoteException{
8+
System.out.println("Hello, Haresh Here");
9+
}
10+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
import java.rmi.RemoteException;
2+
import java.rmi.registry.Registry;
3+
import java.rmi.registry.LocateRegistry;
4+
5+
public class Server {
6+
public static void main(String args[]) throws RemoteException{
7+
Registry registry = LocateRegistry.createRegistry(6001);
8+
registry.rebind("Hello",new Servant());
9+
}
10+
}

0 commit comments

Comments
 (0)