Single Server Queuing Model
Single Server Queuing Model
Description:-
A Queue is a line of people or things to be handled in a sequential order. It is a sequence
of objects that are waiting to be processed. Queuing theory is the study of Queues for managing
process and objects.
The term Queuing system is used to indicate a collection of one or more waiting lines
along with a server or collection of servers that provides service to these waiting lines.
Simulating a Single server queuing model:
A good example to think about for intuition is an ATM machine. We view the machine as
a server that serves customers one at a time. The customers arrive randomly over time and wait
in a queue and upon beginning service, each customers spends a random amount of time in
service before departing.
Source Code:-
Clientcon.java
import java.io.*;
import java.net.*;
class Clientcon
{
public static void main(String arg[]) throws Exception
{
String sentence, newsentence,newsentence1;
DataInputStream in=new DataInputStream(System.in);
Socket cs=new Socket("127.0.0.1",6789);
DataInputStream inp=new DataInputStream(cs.getInputStream());
DataOutputStream out=new DataOutputStream(cs.getOutputStream());
sentence=inp.readLine();
System.out.println(sentence);
newsentence=in.readLine();
out.writeBytes(newsentence+'\n');
newsentence1=inp.readLine();
System.out.println("From Server:"+newsentence1);
cs.close();
}
}
Server.java
import java.io.*;
import java.net.*;
class Server
{
public static void main(String arg[]) throws Exception
{
int count=0;
Thread t= Thread.currentThread();
ServerSocket ss=new ServerSocket(6789);
while(true)
{
try
{
Socket s=ss.accept();
count++;
conserver c =new conserver(s, count);
}
catch(Exception e) {}
}
}
}
}
public void run()
{
try
{
DataInputStream inp=new DataInputStream(s.getInputStream());
DataOutputStream out=new DataOutputStream(s.getOutputStream());
String sentence="Enter the String:";
String newsentence;
out.writeBytes(sentence+'\n');
newsentence=inp.readLine();
//Thread.sleep(10000);
System.out.println("From Client"+c+":"+newsentence);
out.writeBytes(newsentence+'\n');
}
catch(Exception e) {}
}
}
Input/Output Specification:-
Server:
C:\Users\cseadmin\Desktop>java Server
From Client2: 1. Hai
From Client1: 2. Hello
From Client3: 3. Bye
Client 1:
C:\Users\cseadmin\Desktop>java Clientcon
Enter the String:
2. Hello
From Server:2. Hello
Client 2:
C:\Users\cseadmin\Desktop>java Clientcon
Enter the String:
1. Hai
From Server:1. Hai
Client 3:
C:\Users\cseadmin\Desktop>java Clientcon
Enter the String:
3. Bye
From Server:3. Bye
Result/Conclusion:
Hence, the program that implements Single Server Queuing Model was successfully
executed.