Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
Tarea2-RC-Grupo25-Cliente
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Ramiro Facundo Lorenzo Rodriguez Inthamoussu
Tarea2-RC-Grupo25-Cliente
Commits
6fc503cf
Commit
6fc503cf
authored
7 years ago
by
Leonardo
Browse files
Options
Downloads
Patches
Plain Diff
Mergie a mano lo de todo en single file y lo de manejo errores
parent
c8071e84
Branches
soingle-file-client
Branches containing commit
No related tags found
1 merge request
!4
Single file y manejo errores
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tarea2-RC-Grupo25-Cliente.cpp
+36
-11
36 additions, 11 deletions
src/Tarea2-RC-Grupo25-Cliente.cpp
with
36 additions
and
11 deletions
src/Tarea2-RC-Grupo25-Cliente.cpp
+
36
−
11
View file @
6fc503cf
...
...
@@ -78,10 +78,13 @@ void TCP(const char* HOST){
hints
.
ai_socktype
=
SOCK_STREAM
;
getaddrinfo
(
HOST
,
STR
(
TCP_PORT
),
&
hints
,
&
res
);
//primitiva CONNECT
connect
(
client_socket
,
res
->
ai_addr
,
res
->
ai_addrlen
);
printf
(
"Intentando conexion con %s:%d ...
\n
"
,
HOST
,
TCP_PORT
);
printf
(
"Intentando conexion con %s:%d
\n
"
,
HOST
,
TCP_PORT
);
//primitiva CONNECT
if
(
connect
(
client_socket
,
res
->
ai_addr
,
res
->
ai_addrlen
)
<
0
){
printf
(
"Error, imposible establecer conexion con el servidor.
\n
"
);
return
;
}
//primitiva SEND
char
msg
[
4
];
...
...
@@ -91,11 +94,10 @@ void TCP(const char* HOST){
int
msg_size
=
strlen
(
msg
);
int
sent_msg_size
=
send
(
client_socket
,
msg
,
msg_size
,
0
);
if
(
sent_msg_size
==
-
1
)
{
printf
(
"E
RROR:
imposible establecer conexion con el servidor"
);
printf
(
"E
rror,
imposible establecer conexion con el servidor
.
\n
"
);
return
;
}
printf
(
"Conexion establecida con %s:%d
\n
"
,
HOST
,
TCP_PORT
);
printf
(
"Conexion establecida.
\n
"
);
char
buf
[
MAXLEN
];
// se almacenan los datos TCP recibidos en cada recv
char
recibido
[
MAXLEN
];
// mantiene el historico de datos recibidos, quitando los frames ya dibujados
...
...
@@ -161,15 +163,28 @@ void UDP(char* HOSTNAME){
sprintf
(
buffer
,
"subscription"
);
// ENVIO PEDIDO DE SUSCRIPCION
printf
(
"
Sending
Su
b
scrip
t
ion
\n
"
);
printf
(
"
Enviando
Suscrip
c
ion
a %s:%d ...
\n
"
,
HOSTNAME
,
UDP_PORT
);
::
fflush
(
stdout
);
if
(
sendDatagramUDPtoHostname
(
sock
,
HOSTNAME
,
buffer
,
UDP_PORT
)
<
0
)
error
(
"Error on send first datagram"
);
// ESPERO RESPUESTA DEL SERVIDOR
struct
timeval
timeout
;
timeout
.
tv_sec
=
5
;
timeout
.
tv_usec
=
0
;
setsockopt
(
sock
,
SOL_SOCKET
,
SO_RCVTIMEO
,
&
timeout
,
sizeof
(
timeout
));
bzero
(
buffer
,
256
);
struct
sockaddr_in
from
;
if
(
recvfrom
(
sock
,
buffer
,
256
,
0
,(
struct
sockaddr
*
)
&
from
,
&
length
)
<
0
)
error
(
"recvfrom"
);
if
(
recvfrom
(
sock
,
buffer
,
256
,
0
,(
struct
sockaddr
*
)
&
from
,
&
length
)
<
0
){
if
((
errno
==
EAGAIN
)
||
(
errno
==
EWOULDBLOCK
)){
printf
(
"Error, no hay respuesta del servidor.
\n
"
);
return
;
}
else
{
printf
(
"Error al recibir datos.
\n
"
);
return
;
}
}
else
printf
(
"Listo"
);
printf
(
"Subscription: %s
\n
"
,
buffer
);
char
*
keepAliveId
=
new
char
[
3
];
...
...
@@ -194,10 +209,20 @@ void UDP(char* HOSTNAME){
int
fin
=
0
;
// Mantiene el indice del array recibido.
int
received_data_size
=
1
;
while
(
received_data_size
>
0
)
while
(
true
)
{
received_data_size
=
recvfrom
(
sock
,
buf
,
MAXLEN
,
0
,
(
struct
sockaddr
*
)
&
from
,
&
length
);
if
(
received_data_size
<
1
){
if
((
received_data_size
<
0
)
&&
((
errno
==
EAGAIN
)
||
(
errno
==
EWOULDBLOCK
))){
printf
(
"Error, no hay respuesta del servidor.
\n
"
);
return
;
}
else
{
printf
(
"Error al recibir datos.
\n
"
);
return
;
}
}
else
fin
=
printFrame
(
received_data_size
,
recibido
,
fin
,
buf
);
}
//while (true)
...
...
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