0% found this document useful (0 votes)
132 views

Raport: Lalucrarea de Laborator Nr. 6 Tema: Implementarea Aplicaţiilor Client-Server Multi-Thread

This document contains a lab report for an implementation of a client-server application with multi-threading functionality. The server simulates an ATM that allows clients to make withdrawals, deposits, and view transaction histories. The server uses threading to handle concurrent client requests. Clients authenticate with an account number and password before selecting an operation. Transaction histories are synchronized for access and deposit/withdrawal totals are calculated using threads. The server code provided implements this functionality with a threaded server class handling client connections and processing requests.
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)
132 views

Raport: Lalucrarea de Laborator Nr. 6 Tema: Implementarea Aplicaţiilor Client-Server Multi-Thread

This document contains a lab report for an implementation of a client-server application with multi-threading functionality. The server simulates an ATM that allows clients to make withdrawals, deposits, and view transaction histories. The server uses threading to handle concurrent client requests. Clients authenticate with an account number and password before selecting an operation. Transaction histories are synchronized for access and deposit/withdrawal totals are calculated using threads. The server code provided implements this functionality with a threaded server class handling client connections and processing requests.
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/ 4

Ministerul Educaţiei si Cercetarii al Republicii Moldova

Universitatea Tehnică a Moldovei


Catedra Calculatoare

Raport
lalucrarea de laborator Nr. 6

Tema: Implementarea aplicaţiilor client-server


multi-thread

A efecuat: st. gr. C-161, Gangan Eugeniu

A verificat: conf.univ.doctor Rotaru Lilia

Chişinău 2018
Probleme propuse:
6. Se cere elaborarea unei perechi de programe client-server cu următoarea
funcţionalitate:
- serverul simulează un ghişeu de bancă la care se pot face extrageri de
numerar, respectiv alimentări de cont.
- clienţii se autentifică pe baza unui număr de cont şi a unei parole şi pe
lângă cele două operaţii menţionate (extragere/alimentare) pot cere şi un
istoric al tranzacţiilor (listarea tuturor tranzacţiilor, însumarea tuturor
depunerilor/extragerilor).
OBS. Se cere scrierea unui server concurent folosind thread-uri. Accesul la lista
de clienţi şi la istoricul tranzacţiilor va fi sincronizat. Însumarea
depunerilor/extragerilor se va face folosind thread-uri/procese.
Serverul
import java.io.*;
import java.net.*;
import java.util.*;

public class Server extends Thread


{
private static Scanner in= new Scanner(System.in);
private static float balance = 0;
private static int anotherTransaction;
ServerSocket ss;
Socket s;
DataInputStream dis;
DataOutputStream dout;
public Server()
{
try
{
System.out.println("Server Started");
ss=new ServerSocket(2100);
s=ss.accept();
System.out.println(s);
System.out.println("CLIENT CONNECTED");
dis= new DataInputStream(s.getInputStream());
dout= new DataOutputStream(s.getOutputStream());
}
catch(Exception e)
{
System.out.println(e);
}

}
@Override
public void run ()
{
int choice;
choice = in.nextInt();
while(true)
{
try
{
switch(choice)
{
case 1:
float amount;
System.out.println("Please enter amount to withdraw : ");
amount = in.nextFloat();
if(amount > balance || amount == 0)
{
dis.readFloat();
System.out.println("You have insufficient funds\n\n");
anotherTransaction();
}
else
{
balance = balance - amount;
dis.readFloat();
System.out.println("You have withdraw " + amount + " and your
new balance is "+balance+"\n");
anotherTransaction();
}
break;
case 2:
float deposit;
System.out.println("Please enter amount you would with to deposit:
");
deposit = in.nextFloat();
balance = deposit + balance;
dis.readFloat();
System.out.println("You have deposited "+deposit+" new balance is
"+balance+"\n");
anotherTransaction();
break;
case 3:
System.out.println("Your balance is "+balance+"\n");
dis.readFloat();
anotherTransaction();
break;
default:
dout.writeUTF("Invalid option:\n\n");
anotherTransaction();
break;
}
}
catch(IOException e) { e.printStackTrace();}
}
}
private void anotherTransaction()
{
System.out.println("Do you want another transaction?\n\nPress 1 for another
transaction\n2 To exit");
anotherTransaction = in.nextInt();
if(anotherTransaction == 1) { run(); }
else if(anotherTransaction == 2) {System.out.println("Thanks for choosing us.
Good Bye!");}
else
{
System.out.println("Invalid choice\n\n");
anotherTransaction();
}
}
public static void main (String[] args)
{
Server t = new Server();
t.start();
new Server();
}
}

You might also like