Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /**
- **Proyecto: Algoritmo distribuido
- **Materia: Laboratorio de Sistemas Distribuidos y Paralelos
- **Jueves V1
- **Equipo: 3
- ** Gabriela Martinez Aldape
- ** Karen Alduncin Ibarra
- ** Mario Morales Nieto
- **/
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.DataOutputStream;
- import java.net.*;
- import java.awt.event.ActionEvent;
- import java.io.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.FocusEvent;
- import java.net.Socket;
- public class Cliente{
- public static void main (String [] args ) throws Exception {
- File archivo1 = null;//se definen variables para leer un archivo
- FileReader fr1 = null;//definimos lector
- BufferedReader br1 = null;//definimos buffer para lectura
- int t=0;
- double suma=0,sumatotal=0;
- ObjectOutputStream oos = null;
- ObjectInputStream ois = null;
- DataOutputStream dos = null;
- int tamaño=999999999;
- int leo;
- int contados = 0;
- /**
- PARTE DEL CODIGO EN DONDE SE MODIFICARAN LAS DIRECCIONES IP DE LOS INVOLUCRADOS PARA REALIZAR LA CONEXION CORRECTAMENTE
- **/
- Socket socket = new Socket("169.254.123.79",800);
- System.out.println("Conectando...");//informativo :P
- System.out.println("...");
- System.out.println("Conectado...");
- byte [] arreglo = new byte [tamaño];
- InputStream entra = socket.getInputStream();
- /**
- EDITAR LA DIRECCION DEL ARCHIVO DE TEXTO EL CUAL SERA NUESTRA SALIDA DEL PROGRAMA
- **/
- FileOutputStream salida = new FileOutputStream("C:/Users/GABY/Desktop/GananciasGas.txt");
- BufferedOutputStream buf = new BufferedOutputStream(salida);
- leo = entra.read(arreglo,0,arreglo.length);
- contados = leo;
- //realiza la lectura de los datos
- do {
- leo =entra.read(arreglo, contados, (arreglo.length-contados));
- if(leo >= 0) contados += leo;
- } while(leo > -1);
- buf.write(arreglo, 0 , contados);//lo escribe en el buffer
- buf.flush();//limpia la memoria del buffer
- /**
- EDITAR LA DIRECCION DEL ARCHIVO DE TEXTO AL CUAL LE DAREMOS ENTRADA
- **/
- archivo1 = new File ("C:/Users/GABY/Desktop/GananciasGas.txt");
- fr1 = new FileReader (archivo1);
- br1 = new BufferedReader(fr1);
- /**
- Aqui se realiza la suma de las ganancias de la empresa en cuestion
- **/
- String linea1;
- while((linea1=br1.readLine())!=null)
- {
- //System.out.println(linea1);
- suma = Double.parseDouble(linea1);
- sumatotal = sumatotal + suma;
- t++;
- }
- System.out.println("Suma Total: "+sumatotal);
- //System.out.println(t);
- double sp = sumatotal;
- dos = new DataOutputStream(socket.getOutputStream());
- dos.writeDouble(sp);
- /**
- Se cierra buffer, sockets y toda la comunicacion con el servidor.
- **/
- buf.close();
- socket.close();
- /**
- EDITAR LA DIRECCION IP del socket
- **/
- Socket socket1 = new Socket("169.254.123.79",900);
- dos = new DataOutputStream(socket1.getOutputStream());
- dos.writeDouble(sp);
- socket1.close();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement