0% found this document useful (0 votes)
33 views6 pages

TD5 Jerimy Moreira

The document appears to be a university assignment containing the names of the student and professor. It lists the university ("Universidad Tecnica de Manabi"), the professor's name ("Miguel Rodriguez"), and the student's names ("Jerimy Isaac Moreira Alcivar").
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
33 views6 pages

TD5 Jerimy Moreira

The document appears to be a university assignment containing the names of the student and professor. It lists the university ("Universidad Tecnica de Manabi"), the professor's name ("Miguel Rodriguez"), and the student's names ("Jerimy Isaac Moreira Alcivar").
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 6

UNIVERSIDAD

TECNICA DE
MANABI.

DOCENTE: Miguel Rodriguez.

NOMBRES:
Jerimy Isaac Moreira Alcivar.
Servidor:
package ProgramaSTCP;
import com.sun.source.tree.TryTree;
import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.ServerSocket;
import java.net.Socket;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ServidorTCP {

public static void main(String[] args) {


ServerSocket servidor = null;
Socket sc = null;
DataInputStream in;
DataOutputStream out;
final int PUERTO = 5000;

try{
servidor = new ServerSocket(PUERTO);
System.out.println("Servidor Iniciado");

while (true){
sc = servidor.accept();
System.out.println("Cliente Conectado");
in = new DataInputStream(sc.getInputStream());
out = new DataOutputStream(sc.getOutputStream());

String mensaje = in.readUTF();

System.out.println(mensaje);
out.writeUTF("¡Saludos de parte del servidor!");

while (true){
try{
mensaje = in.readUTF();
System.out.println(mensaje);
if("BYE".equals(mensaje))break;

}catch(IOException e){break;
}

}
sc.close();

System.out.println("Cliente Descnoectado");
}
}
catch(IOException ex){
Logger.getLogger(ServidorTCP.class.getName()).log(Level.SEVERE, null, ex);
}
}

Cliente:
package ProgramaSTCP;

import java.io.DataInputStream;
import java.io.DataOutputStream;
import java.io.IOException;
import java.net.Socket;
import java.util.Scanner;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ClienteTCP {

public static void main(String[] args){

final String HOST = "127.0.0.1";


final int PUERTO = 5000;
DataInputStream in;
DataOutputStream out;

try{
Socket sc = new Socket(HOST, PUERTO);
in = new DataInputStream(sc.getInputStream());
out = new DataOutputStream(sc.getOutputStream());

out.writeUTF("Saludos de parte del CLIENTE");

String mensaje = in.readUTF();


System.out.println(mensaje);

Scanner scan = new Scanner(System.in);

int c=1, a=0;

while(c==1){
a=a+1;
System.out.println("Ingrese mensaje");
mensaje = scan.nextLine();
out.writeUTF("Este es el mejor numero"+a+":"+mensaje+"\n");
if(mensaje.equals("Bye"))break;
}
sc.close();

}catch(IOException ex){
Logger.getLogger(ClienteTCP.class.getName()).log(Level.SEVERE, null, ex);
}

}
}
LINK:
https://drive.google.com/drive/folders/1uDUQIR_mLuwK1HqZOLXnl7W-
o0dygA71?usp=drive_link

You might also like