Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
S
SDIS1
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
davidel
SDIS1
Commits
d971f74c
Commit
d971f74c
authored
Feb 26, 2024
by
deivih84
Browse files
Options
Downloads
Patches
Plain Diff
Primer commit para el yit
parent
63d3b5bd
No related branches found
No related tags found
No related merge requests found
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/pacashe/Cliente.java
+22
-0
22 additions, 0 deletions
src/pacashe/Cliente.java
src/pakasheServidor/Servidor.java
+25
-0
25 additions, 0 deletions
src/pakasheServidor/Servidor.java
src/pakasheServidor/ServidorMultihenebrado.java
+41
-0
41 additions, 0 deletions
src/pakasheServidor/ServidorMultihenebrado.java
with
88 additions
and
0 deletions
src/pacashe/Cliente.java
0 → 100644
+
22
−
0
View file @
d971f74c
package
pacashe
;
public
class
Cliente
{
public
static
final
int
PUERTO
=
2000
;
public
static
void
main
(
String
[]
args
)
{
String
linea
;
try
{
java
.
io
.
BufferedReader
tec
=
new
java
.
io
.
BufferedReader
(
new
java
.
io
.
InputStreamReader
(
System
.
in
));
java
.
net
.
Socket
miSocket
=
new
java
.
net
.
Socket
(
"localhost"
,
PUERTO
);
java
.
io
.
BufferedReader
inred
=
new
java
.
io
.
BufferedReader
(
new
java
.
io
.
InputStreamReader
(
miSocket
.
getInputStream
()));
java
.
io
.
PrintStream
outred
=
new
java
.
io
.
PrintStream
(
miSocket
.
getOutputStream
());
while
((
linea
=
tec
.
readLine
())
!=
null
)
{
// lee de teclado
outred
.
println
(
linea
);
// envia al servidor
linea
=
inred
.
readLine
();
// lee del servidor
System
.
out
.
println
(
"Recibido: "
+
linea
);
// eco local del servidor
}
}
catch
(
Exception
e
)
{
System
.
out
.
println
(
"macarrones"
);
}
}
}
This diff is collapsed.
Click to expand it.
src/pakasheServidor/Servidor.java
0 → 100644
+
25
−
0
View file @
d971f74c
package
pakasheServidor
;
public
class
Servidor
{
public
static
final
int
PUERTO
=
2000
;
public
static
void
main
(
String
[]
args
)
{
try
(
java
.
net
.
ServerSocket
servidor
=
new
java
.
net
.
ServerSocket
(
PUERTO
))
{
System
.
out
.
println
(
"----Servidor esperando al cliente ----"
);
try
(
java
.
net
.
Socket
sock
=
servidor
.
accept
())
{
java
.
io
.
BufferedReader
inred
=
new
java
.
io
.
BufferedReader
(
new
java
.
io
.
InputStreamReader
(
sock
.
getInputStream
()));
java
.
io
.
PrintStream
outred
=
new
java
.
io
.
PrintStream
(
sock
.
getOutputStream
());
String
linea
;
while
((
linea
=
inred
.
readLine
())
!=
null
)
{
// lee de la red
System
.
out
.
println
(
"Echoing: "
+
linea
);
// echo por la pantalla
outred
.
println
(
linea
);
// echo al cliente
}
}
catch
(
java
.
io
.
IOException
e
)
{
System
.
err
.
println
(
"Cerrando socket de cliente"
);
e
.
printStackTrace
(
System
.
err
);
}
}
catch
(
java
.
io
.
IOException
e
)
{
System
.
err
.
println
(
"Cerrando socket de servicio"
);
e
.
printStackTrace
(
System
.
err
);
}
}
}
This diff is collapsed.
Click to expand it.
src/pakasheServidor/ServidorMultihenebrado.java
0 → 100644
+
41
−
0
View file @
d971f74c
package
pakasheServidor
;
import
java.io.IOException
;
public
class
ServidorMultihenebrado
{
public
static
final
int
PUERTO
=
2000
;
public
static
void
main
(
String
[]
args
)
throws
IOException
{
try
(
java
.
net
.
ServerSocket
servidor
=
new
java
.
net
.
ServerSocket
(
PUERTO
))
{
while
(
true
)
{
try
{
System
.
out
.
println
(
"----Servidor esperando al cliente ----"
);
java
.
net
.
Socket
sock
=
servidor
.
accept
();
// ojito ! sin try-with-rc
java
.
io
.
BufferedReader
inred
=
new
java
.
io
.
BufferedReader
(
new
java
.
io
.
InputStreamReader
(
sock
.
getInputStream
()));
java
.
io
.
PrintStream
outred
=
new
java
.
io
.
PrintStream
(
sock
.
getOutputStream
());
Runnable
sirviente
=
()
->
{
try
{
String
linea
;
while
((
linea
=
inred
.
readLine
())
!=
null
)
{
System
.
out
.
println
(
"Echoing: "
+
linea
);
outred
.
println
(
linea
);
}
}
catch
(
java
.
io
.
IOException
ioe
)
{
System
.
err
.
println
(
"Cerrando socket de cliente"
);
ioe
.
printStackTrace
(
System
.
err
);
}
};
Thread
t
=
new
Thread
(
sirviente
,
"Sirviente echo"
);
t
.
start
();
}
catch
(
java
.
io
.
IOException
e
)
{
System
.
err
.
println
(
"Cerrando socket de cliente"
);
e
.
printStackTrace
(
System
.
err
);
}
}
// fin del while()
}
catch
(
java
.
io
.
IOException
e
)
{
System
.
err
.
println
(
"Cerrando socket de servicio"
);
e
.
printStackTrace
(
System
.
err
);
}
}
}
\ No newline at end of file
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment