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
0
Issue boards
Milestones
Wiki
Code
Merge requests
0
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
1ce27bd7
Commit
1ce27bd7
authored
7 years ago
by
Ramiro Facundo Lorenzo Rodriguez Inthamoussu
Browse files
Options
Downloads
Patches
Plain Diff
SERVICIO UDP TERMINADO
parent
6a7573d2
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
src/Clients.cpp
+61
-60
61 additions, 60 deletions
src/Clients.cpp
src/Clients.h
+2
-0
2 additions, 0 deletions
src/Clients.h
with
63 additions
and
60 deletions
src/Clients.cpp
+
61
−
60
View file @
1ce27bd7
...
...
@@ -47,20 +47,17 @@ void* keepAliveMethod(void* ptr);
int
findPosDelimiter
(
const
char
*
array
,
int
len
,
int
inicio
)
{
int
i
=
-
1
;
int
pos
=
0
;
for
(
i
=
inicio
;
i
<
len
;
i
++
)
{
if
(
sizeof
(
delimiter
)
-
1
==
pos
)
{
if
(
array
[
i
]
==
delimiter
[
pos
])
{
for
(
i
=
inicio
;
i
<
len
;
i
++
){
if
(
sizeof
(
delimiter
)
-
1
==
pos
)
if
(
array
[
i
]
==
delimiter
[
pos
])
return
i
-
sizeof
(
delimiter
)
+
2
;
}
else
{
else
pos
=
0
;
}
}
else
{
if
(
array
[
i
]
==
delimiter
[
pos
])
{
else
if
(
array
[
i
]
==
delimiter
[
pos
])
pos
++
;
}
else
{
else
pos
=
0
;
}
}
}
return
-
1
;
}
...
...
@@ -94,66 +91,56 @@ void TCP(const char* HOST){
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
int
fin
=
0
;
// Mantiene el indice del array recibido.
double
fpms
=
1000
/
30
;
//frames for ms
int
received_data_size
=
1
;
while
(
received_data_size
>
0
)
{
//primitiva RECEIVE
int
data_size
=
MAXLEN
;
received_data_size
=
recv
(
client_socket
,
buf
,
data_size
,
0
);
fin
=
printFrame
(
received_data_size
,
recibido
,
fin
,
buf
);
}
printf
(
"Datos recibidos: %d
\n
"
,
received_data_size
);
// en el arrray 'recibido' se mantiene los datos que ya exisitian mas los nuevos.
for
(
int
j
=
0
;
j
<
received_data_size
;
j
++
)
{
recibido
[
fin
+
j
]
=
buf
[
j
];
}
fin
=
fin
+
received_data_size
;
int
inicio
=
0
;
int
found
=
-
1
;
while
((
found
=
findPosDelimiter
(
recibido
,
fin
+
1
,
inicio
))
!=
-
1
)
{
char
jpg
[
found
-
inicio
];
for
(
int
h
=
0
;
h
<
found
-
inicio
;
h
++
)
{
jpg
[
h
]
=
recibido
[
inicio
+
h
];
}
printf
(
"Nuevo jpeg size: %li
\n
"
,
sizeof
(
jpg
));
namedWindow
(
"cliente"
,
CV_WINDOW_AUTOSIZE
);
Mat
rawData
=
Mat
(
1
,
found
,
CV_8UC1
,
jpg
);
Mat
frame
=
imdecode
(
rawData
,
CV_LOAD_IMAGE_COLOR
);
imshow
(
"cliente"
,
frame
);
waitKey
(
fpms
);
close
(
client_socket
);
freeaddrinfo
(
res
);
inicio
=
found
+
sizeof
(
delimiter
)
-
1
;
}
}
if
(
inicio
!=
0
)
{
// mueve los datos recibidos al inicio, quitando el (o los) frame dibujado y el delimitador
for
(
int
d
=
inicio
;
d
<
fin
+
1
;
d
++
)
{
recibido
[
d
-
inicio
]
=
recibido
[
d
];
}
fin
=
fin
-
inicio
;
}
int
printFrame
(
int
received_data_size
,
char
*
recibido
,
int
fin
,
char
*
buf
){
double
fpms
=
1000
/
30
;
//frames for ms
printf
(
"Datos recibidos: %d
\n
"
,
received_data_size
);
// en el arrray 'recibido' se mantiene los datos que ya exisitian mas los nuevos.
for
(
int
j
=
0
;
j
<
received_data_size
;
j
++
)
recibido
[
fin
+
j
]
=
buf
[
j
];
fin
+=
received_data_size
;
int
inicio
=
0
;
int
found
=
-
1
;
while
((
found
=
findPosDelimiter
(
recibido
,
fin
+
1
,
inicio
))
!=
-
1
)
{
char
jpg
[
found
-
inicio
];
for
(
int
h
=
0
;
h
<
found
-
inicio
;
h
++
)
jpg
[
h
]
=
recibido
[
inicio
+
h
];
printf
(
"Nuevo jpeg size: %li
\n
"
,
sizeof
(
jpg
));
namedWindow
(
"cliente"
,
CV_WINDOW_AUTOSIZE
);
Mat
rawData
=
Mat
(
1
,
found
,
CV_8UC1
,
jpg
);
Mat
frame
=
imdecode
(
rawData
,
CV_LOAD_IMAGE_COLOR
);
imshow
(
"cliente"
,
frame
);
waitKey
(
fpms
);
inicio
=
found
+
sizeof
(
delimiter
)
-
1
;
}
close
(
client_socket
);
freeaddrinfo
(
res
);
if
(
inicio
!=
0
)
{
// mueve los datos recibidos al inicio, quitando el (o los) frame dibujado y el delimitador
for
(
int
d
=
inicio
;
d
<
fin
+
1
;
d
++
)
recibido
[
d
-
inicio
]
=
recibido
[
d
];
fin
-=
inicio
;
}
return
fin
;
}
void
UDP
(
char
*
HOSTNAME
){
unsigned
int
length
;
struct
from
;
...
...
@@ -196,15 +183,29 @@ void UDP(char* HOSTNAME){
char
*
frameBuffer
=
new
char
[
100
];
while
(
true
)
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
int
fin
=
0
;
// Mantiene el indice del array recibido.
int
received_data_size
=
1
;
while
(
received_data_size
>
0
)
{
memset
(
frameBuffer
,
'\0'
,
100
);
if
(
recvfrom
(
sock
,
frameBuffer
,
100
,
0
,
(
struct
sockaddr
*
)
&
from
,
&
length
)
<
0
)
error
(
"recv from UDP frames"
);
printf
(
"%s
\n
"
,
frameBuffer
);
received_data_size
=
recvfrom
(
sock
,
buf
,
MAXLEN
,
0
,
(
struct
sockaddr
*
)
&
from
,
&
length
);
fin
=
printFrame
(
received_data_size
,
recibido
,
fin
,
buf
);
}
//while (true)
//{
// memset ( frameBuffer , '\0' , 100 );
// if ( recvfrom( sock , frameBuffer , 100 , 0 , (struct sockaddr *)&from , &length ) < 0)
// error("recv from UDP frames");
// printf("%s\n", frameBuffer);
//}
close
(
sock
);
}
...
...
This diff is collapsed.
Click to expand it.
src/Clients.h
+
2
−
0
View file @
1ce27bd7
...
...
@@ -4,6 +4,8 @@
#define UDP_PORT 9998
#define TCP_PORT 9999
int
printFrame
(
int
received_data_size
,
char
*
recibido
,
int
fin
,
char
*
buf
);
void
TCP
(
const
char
*
HOST
);
void
UDP
(
char
*
HOSTNAME
);
...
...
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