Synopsis
Over the years, the evolution of computers has evolved with diskless computers too. Diskless computer does not contain any hard disk. Such a computer is dependent upon another computer (may be a server) for booting. Thus it gets booted through The Preboot execution Environment (PXE, pronounced pixie and also known as Pre-Execution Environment) which is an environment to Boot Computer using a network interface. Diskless booting uses a remote system or systems to store the kernel and the file system that will be used on other computer(s).
Now a day a diskless environment is present for only single server and multiple clients, wherein the clients get booted with one server either Linux or Windows and get access to that particular OS. In this project, that is, “Customized Diskless Computer Environment”, the system has been setup for more than one operating system which may be available in the network, for e.g. Linux & Windows respectively. The uniqueness of this system is to implement a diskless client will get started before getting booted to one operating system and will give an option to the user which operating system he/she wants to use, and will proceed to boot the desired one.
Problem Definition
The main problem faced by most of the system administrators is setting up the lab with required operating systems and other necessary softwares. The current research project is to determine proper solutions in handling the above scenario by minimizing the time, cost and the labour. Ones such solution is to have a diskless computer environment which will enable the administrators to set the system by installing the operating system and softwares in respective servers alone.
The project tries to establish such an environment in which we have to build only two Computer systems, one PC with Windows operating system and other one with Linux operating system or any other operating system that you want. After installation of OS in the two servers, install required softwares and other applications needed by client, and connect to the environment and it is available with full featured Operating system. Thus we are able to create two computers with desired OS, instead of going to each client and installing OS and other applications. Any client connected to the server can now access the OS.
Objective & Scopes
The Aim behind developing a customized diskless computer environment is to save the time of system administrator as well as to bring down the cost incurred in client computers.
In a situation where a system administrator is responsible for setting up and managing nearly 30 to 40 computers in a lab or work environment, it is very time consuming to configure and install each client computer with necessary software’s and network configurations. This is where the role of customized diskless computer environment comes into picture. Here, the administrator just has to prepare two computer machines with desired operating system and all required applications. In this Environment any updates or changes have to be made or can be made on server machine and it will reflect the same updates and changes to all other clients or computers in this Network.
The main objective of the customized diskless environment is very useful in organization or any computer institute or departmental computer lab to make them hardware cost effective.
Through customized diskless computer environment the hardware cost gets reduced. Suppose any organization or institute have some old computers with LAN or PXE booting, then these systems can also be connected to the same network to function as clients and this saves the purchase of new computers.
Due to high flair for computer networking and related environments, we thought of doing a research in existing network settings of the systems and come with a more optimized solution. For this, we had done a survey of some organizations, Institutions (may be a private computer centre or a college computer lab) where we found that there are a number of PCs which are used tremendously for various purposes and application needs are also different. Every system needs a basic Operating system and requires other necessary applications on each one of them. The process of updating the system by the administrator took a long time and that made the users of the system waiting for the job to be done. This motivated us to think of a diskless computing environment.
Our Environment can handle large quantity of clients and requires a good connection with the connectivity say 100 tbase Ethernet. As number of clients increase the booting process will surely get affected. It is better to have high capacity Ethernet hub. Our environment provides two operating systems, and gives an option to choose between two operating systems. In future enhancements we are trying for more operating system i.e., to give more than two operating systems for e.g. Linux, Windows, Mac, and any other version of windows and linux.
One of the major scopes of my customized environment is instead expending several minutes on each client installing Operating system and other necessary software & application we just have to build two computers holding our desired operating system which we offer to client to use. And one more advantage of this is that consider a person coming with diskless CPU and get connected to our environment will get access to more than one operating system.
We just have to remember that we have to keep the server storage enough to hold the load of the network and good speed network connection because same time multiple clients will have access the same operating system
Requirements
· A windows server 2003 system
· An Ubuntu system with (preferably) DHCP and tftpd server.
· At least one PXE-bootable system (the client)
· Enough disk space on the server to hold the client file system
· A fast network connection between the client and the server
· A DHCP server which is capable of supporting PXE clients, or a separate network segment where you can run a dedicated DHCP server
· A good understanding of Linux
Working
Diskless booting requires a DHCP server which is a bootable PXE network card. The client will query to get its configuration and location of the bootable file from tftp server. After booting the PXE image the client will boot the kernel image (with arguments specified in the pxe configuration). Those arguments will tell the kernel how to configure itself, and the path to mount the NFS share where its directory is located. I our environment we are using both LTSP & MTSP for Linux & Windows respectively. As client get Booted it gets an option to choose the desired operating system.
Getting Started
Windows Server 2003 Installation
Start by installing Windows Server 2003 to a physical disk
You can now press Enter to install Windows Server 2003 to this partition. The rest of the installation will proceed as normal.
Windows Server 2003 Startup
Now Windows Server 2003 is setup to use
Ubuntu Server Installation
Ubuntu 9.10, also known as the Karmic Koala, arrived exactly on October 29, 2009 and is the eleventh release of Ubuntu OS. We've created the following tutorial to teach Linux newcomers how to install the
Ubuntu 9.10 operating system on their personal
The tutorial will make things very simple for you, but if you get stuck somewhere in the middle of the installation and you need help, do not hesitate to use our commenting system at the end of the article!
Requirements:
You will need the Ubuntu 9.10 Desktop ISO image that corresponds to your hardware architecture (i386 or amd64). When the download is over, burn the ISO image with your favorite CD/DVD burning application (Nero, CDBurnerXP, Roxio) on a blank CD at 8x speed.
Now u can use Ubuntu 9.10
After Ubuntu installation we have to update through the command (Internet Connection required)
#sudo su
#apt-get update
Now Installing LTSP on top of an already running desktop system through command
#sudo apt-get install ltsp-server-standalone openssh-server
Now create your Thin Client environment on the server with.
sudo ltsp-build-client
this will create a thin client environment on your linux server
Comment: - If you change the IP data after you have done the initial setup, please run the command sudo ltsp-update-sshkeys to make the ssh server aware of the change. This workstation isn't authorized to connect to server error message on client, please run commands sudo ltsp-update-sshkeys and sudo ltsp-update-image.
Preboot eXecution Environment (PXE)
PXE is an open industry standard developed by a number of software and hardware vendors. It was initially designed by Intel, with input from several other vendors including 3Com, HP, Dell, Compaq, and Phoenix Technologies. PXE works with a network interface card (NIC) in the PC, and makes the NIC a boot device. The PXE vision is to "Make the network interface a standard, industry-accepted PC boot device." This means adding the NIC to the traditional list of standard boot devices, such as floppy drives, hard disks, and CD-ROMs, that load the operating system or set up programs on the PC. It allows the client PC to "network boot." Booting from the network opens up a vast array of management and support features.
PXE boots the client PC from the network by transferring a "boot image file" from a server. This file can be the operating system for the client PC or a pre-OS agent (see the section, "Pre-OS," later in this paper) that performs client management tasks. Since PXE is not operating system-specific, the image file can load any OS. It provides support for network booting , of embedded and other operating systems.
Because PXE works with the NIC, it requires a PXE-enabled NIC. Most currently available NICs do support PXE, including those from 3Com, Intel, Digital, RealTek, and SMC. PXE is available either as a boot ROM chip that you add to the NIC, or as part of the system BIOS if the network interface is on the motherboard. PXE is specific to a type of NIC; a boot ROM for one type (for example, a 3C905C) will not work on another type of NIC.
DHCP Configuration
Configure your DHCP server
You need to set up the DHCP server to offer /var/lib/tftpboot/pxelinux.0 as a boot file as a minimum. You also assign a fixed IP to the machine you want to boot with PXE (the client). A range of other options are also available but are beyond the scope of this article. Your dhcpd.conf might look like this assuming your subnet is 192.168.2.0
# gedit /etc/ltsp/dhcpd.conf
After configuration dhcpd.conf file will look something like this.
allow booting;
allow bootp;
subnet 192.168.2.0 netmask 255.255.255.0 {
range 192.168.2.xxx 192.168.2.xxx;
option broadcast-address 192.168.2.255;
option routers 192.168.2.xxx;
option domain-name-servers 192.168.2.xxx;
filename "/pxelinux.0";
}
# force the client to this ip for pxe.
# This is only necessary assuming you want to send different images to different computers.
host pxe_client
{
hardware ethernet xx:xx:xx:xx:xx:xx;
fixed-address 192.168.2.xxx;
}
NOTE 1: You will need to replace the 'xx:xx:xx:xx:xx:xx' and the '192.168.2.xxx' with your own values
NOTE 2: the filename is a relative path to the root of the tftp server.
Pxelinux.cfg/default file Configuration
This is very important file now we have to configure this file so that when PXE booting start its get its instruction through this file, our tftp boot folder is in the directory /var/lib/tftpboot/ltsp/i386/pxelinux.cfg/
Now we have to create default file in this directory
# gedit /var/lib/tftpboot/ltsp/i386/pxelinux.cfg/default
In my environment it look something like this
default vesamenu.c32
Menu Background howtoforge_pxe.png
Menu Title Boot Menu
label Linux
menu label ^Linux
menu default
kernel vmlinuz
append vmlinuz ro initrd=initrd.img – quiet splash
label Windows
menu label ^Windows
kernel vmlinuz2
append ramdisk_size=17232 ro initrd=initrd2.img root=/dev/ram console=null SESSION_DEFAULT=rdp
Now we have put some file required for PXE bootin,some files I have in my /home/mhs directory.
# cp /home/mhs/isolinux/vmlinuz2 /var/lib/tftpboot/ltsp/i386/
# cp /home/mhs/isolinux/initrd2.img /var/lib/tftpboot/ltsp/i386/
# cp /home/mhs/isolinux/vesamenu.c32 /var/lib/tftpboot/ltsp/i386/
# cp /home/mhs/isolinux/MP.png /var/lib/tftpboot/ltsp/i386/
Some files is already present as we install LTSP for terminal services
Tftpboot directory tree will look this
/var
/lib
/tffpboot
/ltsp
/i386/pxelinux.cfg ……………. (it is directory not file)
/default…………. ( This is main config file)
/pxelinux.0
/vmlinuz ……………………. (LTSP kernel)
/initrd.img ………………… (LTSP RAM image file)
/vmlinuz2 …………………… (Our custom kernel)
/initrd2.img ………………… (Our custom RAM image file)
/vesamenu.c32
/MP.png
1.We have to start linux server & put up the static IP Address
In my case I have put
IP = 192.168.2.2
Net mask = 255.255.255.0
DNS Server = 192.168.2.1
After putting this value start the DHCP server
/etc/init.d/dhcp3-server start
/etc/init.d/tftp-hpa start
Booting the Clients
This is our option before getting booted to certain os now we have to choose our desire operating system you want.
Video of this project i will upload it soon.
If u need any extra information on this project feel free to email me.
Wednesday, June 23, 2010
Monday, June 14, 2010
b. Implementation of queue
-------------------------------------------------------------------------------------------------------------
SOURCE CODE
----------------------------------------------------------------------------------------------
Server Program :
import java.io.*;
import java.net.*;
//class implementing Queue operations
class Queue{
private int queue[];
private int toq;
private int eoq;
// allocate and initialize queue
Queue(int size){
queue = new int[size];
toq = 0;
eoq = -1;
}
//check whether queue is full
boolean isFull(){
if(eoq == queue.length-1)
return true;
else
return false;
}
//check whether queue is empty
boolean isEmpty(){
if(eoq < 0)
return true;
else
return false;
}
// Push an item into queue
void push(int item){
for(int i=eoq;i>-1;i--){
queue[i+1]=queue[i];
}
++eoq;
queue[0] = item;
}
// Pop an item from the queue
int pop(){
return queue[eoq--];
}
//get all elements of queue
int[] getQueue(){
return queue;
}
//get current size of queue
int getCurrentSize(){
return (eoq+1);
}
}
//class implementing Queue Server operations
class QueueServer implements Runnable{
static ServerSocket serverSocket;
Socket socket;
BufferedReader read,from;
PrintWriter to;
Thread thread;
Queue queue;
int clientID;
static int clientCounter=0;
//constructor
QueueServer(Socket socket)throws Exception{
this.socket=socket;
clientID=++clientCounter;
System.out.println("New Client connection accepted. ClientID: "+clientID);
from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
to=new PrintWriter(socket.getOutputStream(),true);
thread=new Thread(this);
thread.start();
}
//run() method for each client request thread
public void run(){
try{
to.println("Enter size of the queue: ");
int size=Integer.parseInt((from.readLine()).trim());
queue=new Queue(size);
int item=0;
String action=" ";
to.println("You can \"push\" \"pop\" \"display\" elements or \"exit\" What next??");
do{
action=(from.readLine()).toLowerCase();
if(action.equals("push")){
if(queue.isFull())
to.println("Queue Full. What next??");
else{
to.println("Enter element: ");
item=Integer.parseInt((from.readLine()).trim());
queue.push(item);
to.println("Pushed item. What next??");
}
}
else if(action.equals("pop")){
if(queue.isEmpty())
to.println("Stack Empty. What next??");
else
to.println("Popped item: "+queue.pop()+" What next??");
}
else if(action.equals("display")){
if(queue.isEmpty())
to.println("Queue Empty. What next??");
else{
int[] q=queue.getQueue();
String queueStr="";
for(int i=0;i queueStr=queueStr+" "+q[i];
to.println("Queue contains: "+queueStr+" What next??");
}
}
else if(action.equals("exit")){
socket.close();
break;
}
else
to.println("Invalid option. What next??");
}while(!(action=="exit"));
System.out.println("Client "+clientID+" exited.");
}catch(Exception e){System.out.println(e);}
}
//main() method
public static void main(String args[])throws Exception{
serverSocket=new ServerSocket(2222);
System.out.println("Server Started. Press Ctrl+C to close server.");
while(true){
Socket s=serverSocket.accept();
QueueServer server=new QueueServer(s);
}
}
}
Client Program :
import java.io.*;
import java.net.*;
//class implementing client operations
class QueueClient{
//main() method
public static void main(String args[]){
try{
String in="";
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter server address: ");
Socket socket=new Socket(read.readLine(),2222);
BufferedReader from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter to=new PrintWriter(socket.getOutputStream(),true);
//read write loop of client
while(true){
System.out.println(from.readLine());
in=read.readLine();
to.println(in);
if(in.equalsIgnoreCase("exit")){
socket.close();
break;
}
}
System.out.println("Client closing.");
}catch(Exception e){e.printStackTrace(System.out);}
}
}
-------------------------------------------------------------------------------------------------------------
SOURCE CODE
----------------------------------------------------------------------------------------------
Server Program :
import java.io.*;
import java.net.*;
//class implementing Queue operations
class Queue{
private int queue[];
private int toq;
private int eoq;
// allocate and initialize queue
Queue(int size){
queue = new int[size];
toq = 0;
eoq = -1;
}
//check whether queue is full
boolean isFull(){
if(eoq == queue.length-1)
return true;
else
return false;
}
//check whether queue is empty
boolean isEmpty(){
if(eoq < 0)
return true;
else
return false;
}
// Push an item into queue
void push(int item){
for(int i=eoq;i>-1;i--){
queue[i+1]=queue[i];
}
++eoq;
queue[0] = item;
}
// Pop an item from the queue
int pop(){
return queue[eoq--];
}
//get all elements of queue
int[] getQueue(){
return queue;
}
//get current size of queue
int getCurrentSize(){
return (eoq+1);
}
}
//class implementing Queue Server operations
class QueueServer implements Runnable{
static ServerSocket serverSocket;
Socket socket;
BufferedReader read,from;
PrintWriter to;
Thread thread;
Queue queue;
int clientID;
static int clientCounter=0;
//constructor
QueueServer(Socket socket)throws Exception{
this.socket=socket;
clientID=++clientCounter;
System.out.println("New Client connection accepted. ClientID: "+clientID);
from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
to=new PrintWriter(socket.getOutputStream(),true);
thread=new Thread(this);
thread.start();
}
//run() method for each client request thread
public void run(){
try{
to.println("Enter size of the queue: ");
int size=Integer.parseInt((from.readLine()).trim());
queue=new Queue(size);
int item=0;
String action=" ";
to.println("You can \"push\" \"pop\" \"display\" elements or \"exit\" What next??");
do{
action=(from.readLine()).toLowerCase();
if(action.equals("push")){
if(queue.isFull())
to.println("Queue Full. What next??");
else{
to.println("Enter element: ");
item=Integer.parseInt((from.readLine()).trim());
queue.push(item);
to.println("Pushed item. What next??");
}
}
else if(action.equals("pop")){
if(queue.isEmpty())
to.println("Stack Empty. What next??");
else
to.println("Popped item: "+queue.pop()+" What next??");
}
else if(action.equals("display")){
if(queue.isEmpty())
to.println("Queue Empty. What next??");
else{
int[] q=queue.getQueue();
String queueStr="";
for(int i=0;i
to.println("Queue contains: "+queueStr+" What next??");
}
}
else if(action.equals("exit")){
socket.close();
break;
}
else
to.println("Invalid option. What next??");
}while(!(action=="exit"));
System.out.println("Client "+clientID+" exited.");
}catch(Exception e){System.out.println(e);}
}
//main() method
public static void main(String args[])throws Exception{
serverSocket=new ServerSocket(2222);
System.out.println("Server Started. Press Ctrl+C to close server.");
while(true){
Socket s=serverSocket.accept();
QueueServer server=new QueueServer(s);
}
}
}
Client Program :
import java.io.*;
import java.net.*;
//class implementing client operations
class QueueClient{
//main() method
public static void main(String args[]){
try{
String in="";
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter server address: ");
Socket socket=new Socket(read.readLine(),2222);
BufferedReader from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter to=new PrintWriter(socket.getOutputStream(),true);
//read write loop of client
while(true){
System.out.println(from.readLine());
in=read.readLine();
to.println(in);
if(in.equalsIgnoreCase("exit")){
socket.close();
break;
}
}
System.out.println("Client closing.");
}catch(Exception e){e.printStackTrace(System.out);}
}
}
Simulating Network Operating System (NOS) commands
Simulating Network Operating System (NOS) commands
Concept:
In this practical make use of socket programming. On the client side design an application that will give the list of commands. The client will invoke these commands. On the server side these commands will be executed. The implementation of the above commands will be on the server side.
a. Implementation of stack
Commands: PUSH, POP, DISPLAY, EXIT, etc.
b. Implementation of queue.
Commands: INSERT, DELETE, DISPLAY, EXIT, etc.
a. Implementation of Stack
-----------------------------------------------------------------------------------------------------------
SOURCE CODE
-----------------------------------------------------------------------------------------------------------
Server Program :
import java.io.*;
import java.net.*;
//class implementing Stack operations
class Stack{
private int stck[];
private int tos;
// allocate and initialize stack
Stack(int size){
stck = new int[size];
tos = -1;
}
//check whether stack is full
boolean isFull(){
if(tos == stck.length-1)
return true;
else
return false;
}
//check whether stack is empty
boolean isEmpty(){
if(tos < 0)
return true;
else
return false;
}
// Push an item onto the stack
void push(int item){
if(! (tos==stck.length-1)) // use length member
stck[++tos] = item;
}
// Pop an item from the stack
int pop(){
return stck[tos--];
}
//get entire stack
int[] getStack(){
return stck;
}
//get current size of the stack
int getCurrentSize(){
return (tos+1);
}
}
//class implementing Stack Server operations
class StackServer implements Runnable{
static ServerSocket serverSocket;
Socket socket;
BufferedReader read,from;
PrintWriter to;
Thread thread;
Stack stack;
int clientID;
static int clientCounter=0;
//constructor
StackServer(Socket socket)throws Exception{
this.socket=socket;
clientID=++clientCounter;
System.out.println("New Client connection accepted. ClientID: "+clientID);
from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
to=new PrintWriter(socket.getOutputStream(),true);
thread=new Thread(this);
thread.start();
}
//run() method for each client request thread
public void run(){
try{
to.println("Enter size of the stack: ");
int size=Integer.parseInt((from.readLine()).trim());
stack=new Stack(size);
int item=0;
String action=" ";
to.println("You can \"push\" \"pop\" \"display\" elements or \"exit\" What next??");
do{
action=(from.readLine()).toLowerCase();
if(action.equals("push")){
if(stack.isFull())
to.println("Stack Full. What next??");
else{
to.println("Enter element: ");
item=Integer.parseInt((from.readLine()).trim());
stack.push(item);
to.println("Pushed item. What next??");
}
}
else if(action.equals("pop")){
if(stack.isEmpty())
to.println("Stack Empty. What next??");
else
to.println("Popped item: "+stack.pop()+" What next??");
}
else if(action.equals("display")){
if(stack.isEmpty())
to.println("Stack Empty. What next??");
else{
int[] stck=stack.getStack();
String stckStr="";
for(int i=0;i stckStr=stckStr+" "+stck[i];
to.println("Stack contains: "+stckStr+" What next??");
}
}
else if(action.equals("exit")){
socket.close();
break;
}
else
to.println("Invalid option. What next??");
}while(!(action=="exit"));
System.out.println("Client "+clientID+" exited.");
}catch(Exception e){System.out.println(e);}
}
//main() method
public static void main(String args[])throws Exception{
serverSocket=new ServerSocket(2222);
System.out.println("Server Started. Press Ctrl+C to close server.");
while(true){
Socket s=serverSocket.accept();
StackServer server=new StackServer(s);
}
}
}
Client Program :
import java.io.*;
import java.net.*;
//class implementing Stack Client operations
class StackClient{
//main() method
public static void main(String args[]){
try{
String in="";
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter server address: ");
Socket socket=new Socket(read.readLine(),2222);
BufferedReader from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter to=new PrintWriter(socket.getOutputStream(),true);
//read write loop
while(true){
System.out.println(from.readLine());
in=read.readLine();
to.println(in);
if(in.equalsIgnoreCase("exit")){
socket.close();
break;
}
}
System.out.println("Client closing.");
}catch(Exception e){e.printStackTrace(System.out);}
}
}
Concept:
In this practical make use of socket programming. On the client side design an application that will give the list of commands. The client will invoke these commands. On the server side these commands will be executed. The implementation of the above commands will be on the server side.
a. Implementation of stack
Commands: PUSH, POP, DISPLAY, EXIT, etc.
b. Implementation of queue.
Commands: INSERT, DELETE, DISPLAY, EXIT, etc.
a. Implementation of Stack
-----------------------------------------------------------------------------------------------------------
SOURCE CODE
-----------------------------------------------------------------------------------------------------------
Server Program :
import java.io.*;
import java.net.*;
//class implementing Stack operations
class Stack{
private int stck[];
private int tos;
// allocate and initialize stack
Stack(int size){
stck = new int[size];
tos = -1;
}
//check whether stack is full
boolean isFull(){
if(tos == stck.length-1)
return true;
else
return false;
}
//check whether stack is empty
boolean isEmpty(){
if(tos < 0)
return true;
else
return false;
}
// Push an item onto the stack
void push(int item){
if(! (tos==stck.length-1)) // use length member
stck[++tos] = item;
}
// Pop an item from the stack
int pop(){
return stck[tos--];
}
//get entire stack
int[] getStack(){
return stck;
}
//get current size of the stack
int getCurrentSize(){
return (tos+1);
}
}
//class implementing Stack Server operations
class StackServer implements Runnable{
static ServerSocket serverSocket;
Socket socket;
BufferedReader read,from;
PrintWriter to;
Thread thread;
Stack stack;
int clientID;
static int clientCounter=0;
//constructor
StackServer(Socket socket)throws Exception{
this.socket=socket;
clientID=++clientCounter;
System.out.println("New Client connection accepted. ClientID: "+clientID);
from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
to=new PrintWriter(socket.getOutputStream(),true);
thread=new Thread(this);
thread.start();
}
//run() method for each client request thread
public void run(){
try{
to.println("Enter size of the stack: ");
int size=Integer.parseInt((from.readLine()).trim());
stack=new Stack(size);
int item=0;
String action=" ";
to.println("You can \"push\" \"pop\" \"display\" elements or \"exit\" What next??");
do{
action=(from.readLine()).toLowerCase();
if(action.equals("push")){
if(stack.isFull())
to.println("Stack Full. What next??");
else{
to.println("Enter element: ");
item=Integer.parseInt((from.readLine()).trim());
stack.push(item);
to.println("Pushed item. What next??");
}
}
else if(action.equals("pop")){
if(stack.isEmpty())
to.println("Stack Empty. What next??");
else
to.println("Popped item: "+stack.pop()+" What next??");
}
else if(action.equals("display")){
if(stack.isEmpty())
to.println("Stack Empty. What next??");
else{
int[] stck=stack.getStack();
String stckStr="";
for(int i=0;i
to.println("Stack contains: "+stckStr+" What next??");
}
}
else if(action.equals("exit")){
socket.close();
break;
}
else
to.println("Invalid option. What next??");
}while(!(action=="exit"));
System.out.println("Client "+clientID+" exited.");
}catch(Exception e){System.out.println(e);}
}
//main() method
public static void main(String args[])throws Exception{
serverSocket=new ServerSocket(2222);
System.out.println("Server Started. Press Ctrl+C to close server.");
while(true){
Socket s=serverSocket.accept();
StackServer server=new StackServer(s);
}
}
}
Client Program :
import java.io.*;
import java.net.*;
//class implementing Stack Client operations
class StackClient{
//main() method
public static void main(String args[]){
try{
String in="";
BufferedReader read=new BufferedReader(new InputStreamReader(System.in));
System.out.println("Enter server address: ");
Socket socket=new Socket(read.readLine(),2222);
BufferedReader from=new BufferedReader(new InputStreamReader(socket.getInputStream()));
PrintWriter to=new PrintWriter(socket.getOutputStream(),true);
//read write loop
while(true){
System.out.println(from.readLine());
in=read.readLine();
to.println(in);
if(in.equalsIgnoreCase("exit")){
socket.close();
break;
}
}
System.out.println("Client closing.");
}catch(Exception e){e.printStackTrace(System.out);}
}
}
Subscribe to:
Posts (Atom)