Professional Documents
Culture Documents
Practical - 4: Aim: Servers Can Be Designed To Limit The Number of Open Connections. For Example
Practical - 4: Aim: Servers Can Be Designed To Limit The Number of Open Connections. For Example
Practical - 4: Aim: Servers Can Be Designed To Limit The Number of Open Connections. For Example
no:90
Practical -4
Aim : Servers can be designed to limit the number of open connections. For example,
a server may wish to have only N socket connections open at any point in time. After
N connections have been made, the server will not accept another incoming
connection until an existing connection is released. Write Java programs to
demonstrate the scenario
Code :
Client4.java
import java.net.*;
import java.io.*;
class client4 {
//input
while (true) {
System.out.println("CAndroid/CIOS/CQuit");
String line = br1.readLine();
if(line.equalsIgnoreCase("CAndroid")){
System.out.println("Romil");
} else if(line.equalsIgnoreCase("CIOS")){
System.out.println("vora");
} else if(line.equalsIgnoreCase("CQuit")){
System.out.println("Let's Go Home");
System.exit(0);
}
}
} catch (Exception e) {
System.out.println(e);
}
}
Server4.java
import java.net.*;
import java.io.*;
class server4 {
InputStream in = client[i].getInputStream();
InputStreamReader isr = new InputStreamReader(in);
BufferedReader br = new BufferedReader(isr);
//socket output
OutputStream out = client[i].getOutputStream();
PrintWriter pw = new PrintWriter(out, true);
//input
InputStreamReader isr1 = new InputStreamReader(System.in);
BufferedReader br1 = new BufferedReader(isr1);
while (true) {
System.out.println("SAndroid/SIOS/SQuit");
String line = br1.readLine();
if(line.equalsIgnoreCase("SAndroid")){
System.out.println("Romil");
} else if(line.equalsIgnoreCase("SIOS")){
System.out.println("vora");
} else if(line.equalsIgnoreCase("SQuit")){
System.out.println("Let's Go Home");
client[i].close();
System.exit(0);
}
/* switch (line.charAt(0)) {
case 'r':
case 'R':
System.out.println("here");
String input = br.readLine();
System.out.println("ROutput : " + input);
break;
case 's':
case 'S':
String output = br1.readLine();
pw.println(output);
pw.flush();
System.out.println("SOutput : " + output);
break;
case 'q':
case 'Q':
System.out.println("Fin");
client[i].close();
System.exit(0);
}*/
}
}
} catch (Exception e) {
System.out.println(e);
}
}
}
Output :