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.net.*;
- import java.io.*;
- import javax.swing.*;
- import java.awt.*;
- import java.awt.event.ActionEvent;
- import java.awt.event.FocusEvent;
- import java.io.ObjectInputStream;
- import java.io.ObjectOutputStream;
- import java.io.DataInputStream;
- import java.net.Socket;
- public class Servidor {
- public static void main (String [] args ) throws Exception {
- int c = 1;//Inicializamos con un cliente
- double suma = 0;
- ObjectOutputStream oos = null;
- ObjectInputStream ois = null;
- DataInputStream dis = null;
- ServerSocket servidor = new ServerSocket(800);
- ServerSocket serv = new ServerSocket(900);
- /**
- NUMERO DE CLIENTES QUE EL SERVIDOR PODRA ACEPTAR EN ESTE CASO 2.
- **/
- while (c<=2) {
- System.out.println("Esperando...");//informativo
- Socket socket = servidor.accept();
- System.out.println("Conexion Aceptada Desde Direccion IP : " + socket.getInetAddress());
- if(c==1){
- /**
- EDITAR LA DIRECCION DEL ARCHIVO DE TEXTO DE ENTRADA
- **/
- File archivo = new File ("C:/GananciasSuc1.txt");
- byte [] arreglo = new byte [(int)archivo.length()];
- FileInputStream entrada = new FileInputStream(archivo);
- BufferedInputStream buf = new BufferedInputStream(entrada);
- buf.read(arreglo,0,arreglo.length);
- OutputStream envio = socket.getOutputStream();
- System.out.println("Enviado...");//informativo
- envio.write(arreglo,0,arreglo.length);
- envio.flush();
- socket.close();
- }
- else if(c==2){
- /**
- EDITAR LA DIRECCION DEL ARCHIVO DE TEXTO DE ENTRADA
- **/
- File archivo = new File ("C:/GananciasSuc2.txt");
- byte [] arreglo = new byte [(int)archivo.length()];
- FileInputStream entrada = new FileInputStream(archivo);
- BufferedInputStream buf = new BufferedInputStream(entrada);
- buf.read(arreglo,0,arreglo.length);
- OutputStream envio = socket.getOutputStream();
- System.out.println("Enviado...");
- envio.write(arreglo,0,arreglo.length);
- envio.flush();
- socket.close();
- }
- Socket socket1 = serv.accept();
- dis = new DataInputStream(socket1.getInputStream());
- double n = (double)dis.readDouble();
- suma = suma+n;
- /**
- EDITAR LA CANTIDAD DE CLIENTES DE SER NECESARIO
- **/
- if(c==2){
- System.out.println("Cantidad Total Recibida:"+suma);
- }
- c++;
- }
- }
- }
- /**
- **Si es necesario utilizar este programa al implementarlo con
- **mayor cantidad de clientes solo se tendra que agregar el sig.
- **codigo dentro del while(c<=deClientes)teniendo en cuenta una
- **salida de texto para cada uno:
- else if(c==3)
- {
- File archivo = new File ("C:/ArchivoSucursal#.txt");//:3
- byte [] arreglo = new byte [(int)archivo.length()];
- FileInputStream entrada = new FileInputStream(archivo);
- BufferedInputStream buf = new BufferedInputStream(entrada);
- buf.read(arreglo,0,arreglo.length);
- OutputStream envio = socket.getOutputStream();
- System.out.println("Enviado...");
- envio.write(arreglo,0,arreglo.length);
- envio.flush();
- socket.close();
- }else if(c==4)
- {
- File archivo = new File ("C:/ArchivoSucursal#.txt");//:D
- byte [] arreglo = new byte [(int)archivo.length()];
- FileInputStream entrada = new FileInputStream(archivo);
- BufferedInputStream buf = new BufferedInputStream(entrada);
- buf.read(arreglo,0,arreglo.length);
- OutputStream envio = socket.getOutputStream();
- System.out.println("Enviado...");
- envio.write(arreglo,0,arreglo.length);
- envio.flush();
- socket.close();
- }
- **/
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement