[go: up one dir, main page]

0% found this document useful (0 votes)
39 views3 pages

Single Server Queuing Model

The document describes designing and implementing an application for a single server queuing model. It discusses queuing theory and defines a queuing system as having one or more waiting lines and a server to provide service. As an example, it describes an ATM machine with customers arriving randomly to wait in a queue for service. The source code provided implements a single server queuing model with a server and multiple client connections demonstrating the queue. It was successfully executed with the server printing messages received from each client in turn.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
39 views3 pages

Single Server Queuing Model

The document describes designing and implementing an application for a single server queuing model. It discusses queuing theory and defines a queuing system as having one or more waiting lines and a server to provide service. As an example, it describes an ATM machine with customers arriving randomly to wait in a queue for service. The source code provided implements a single server queuing model with a server and multiple client connections demonstrating the queue. It was successfully executed with the server printing messages received from each client in turn.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as DOCX, PDF, TXT or read online on Scribd
You are on page 1/ 3

Aim:- Design and implement an application for 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) {}
}
}
}

class conserver implements Runnable


{
Thread t;
Socket s;
int c;
conserver(Socket s1,int count)
{
t=new Thread(this, "Demo");
t.start();
s=s1;
c=count;

}
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.

You might also like