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
8a1d6cc7
Commit
8a1d6cc7
authored
7 years ago
by
Leonardo
Browse files
Options
Downloads
Patches
Plain Diff
Manejo de error al conectar
parent
1ce27bd7
Branches
master
No related tags found
1 merge request
!2
Manejo de error al conectar
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Clients.cpp
+35
-9
35 additions, 9 deletions
src/Clients.cpp
with
35 additions
and
9 deletions
src/Clients.cpp
+
35
−
9
View file @
8a1d6cc7
...
...
@@ -72,21 +72,25 @@ void TCP(const char* HOST){
hints
.
ai_socktype
=
SOCK_STREAM
;
getaddrinfo
(
HOST
,
STR
(
TCP_PORT
),
&
hints
,
&
res
);
printf
(
"Intentando conexion con %s:%d ...
\n
"
,
HOST
,
TCP_PORT
);
//primitiva CONNECT
connect
(
client_socket
,
res
->
ai_addr
,
res
->
ai_addrlen
);
if
(
connect
(
client_socket
,
res
->
ai_addr
,
res
->
ai_addrlen
)
<
0
){
printf
(
"Error, imposible establecer conexion con el servidor.
\n
"
);
return
;
}
printf
(
"Intentando conexion con %s:%d
\n
"
,
HOST
,
TCP_PORT
);
//primitiva SEND
char
*
msg
=
"TCP"
;
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
...
...
@@ -153,15 +157,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
];
...
...
@@ -189,9 +206,18 @@ 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
);
}
...
...
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