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
4ff0e280
Commit
4ff0e280
authored
7 years ago
by
Ramiro Facundo Lorenzo Rodriguez Inthamoussu
Browse files
Options
Downloads
Patches
Plain Diff
separacion prueba openCV
parent
44e61e7f
No related branches found
No related tags found
No related merge requests found
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
.gitignore
+1
-0
1 addition, 0 deletions
.gitignore
.settings/language.settings.xml
+2
-2
2 additions, 2 deletions
.settings/language.settings.xml
src/PruebaOpenCV.cpp
+224
-0
224 additions, 0 deletions
src/PruebaOpenCV.cpp
src/Tarea2-RC-Grupo25-Cliente.cpp
+6
-211
6 additions, 211 deletions
src/Tarea2-RC-Grupo25-Cliente.cpp
with
233 additions
and
213 deletions
.gitignore
0 → 100644
+
1
−
0
View file @
4ff0e280
/Debug/
This diff is collapsed.
Click to expand it.
.settings/language.settings.xml
+
2
−
2
View file @
4ff0e280
...
...
@@ -5,7 +5,7 @@
<provider
copy-of=
"extension"
id=
"org.eclipse.cdt.ui.UserLanguageSettingsProvider"
/>
<provider-reference
id=
"org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider"
ref=
"shared-provider"
/>
<provider-reference
id=
"org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider"
ref=
"shared-provider"
/>
<provider
class=
"org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector"
console=
"false"
env-hash=
"-1
638737819873243134
"
id=
"org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector"
keep-relative-paths=
"false"
name=
"CDT GCC Built-in Compiler Settings"
parameter=
"${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}""
prefer-non-shared=
"true"
>
<provider
class=
"org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector"
console=
"false"
env-hash=
"-1
704490246509642878
"
id=
"org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector"
keep-relative-paths=
"false"
name=
"CDT GCC Built-in Compiler Settings"
parameter=
"${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}""
prefer-non-shared=
"true"
>
<language-scope
id=
"org.eclipse.cdt.core.gcc"
/>
<language-scope
id=
"org.eclipse.cdt.core.g++"
/>
</provider>
...
...
@@ -16,7 +16,7 @@
<provider
copy-of=
"extension"
id=
"org.eclipse.cdt.ui.UserLanguageSettingsProvider"
/>
<provider-reference
id=
"org.eclipse.cdt.core.ReferencedProjectsLanguageSettingsProvider"
ref=
"shared-provider"
/>
<provider-reference
id=
"org.eclipse.cdt.managedbuilder.core.MBSLanguageSettingsProvider"
ref=
"shared-provider"
/>
<provider
class=
"org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector"
console=
"false"
env-hash=
"-1
638737819873243134
"
id=
"org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector"
keep-relative-paths=
"false"
name=
"CDT GCC Built-in Compiler Settings"
parameter=
"${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}""
prefer-non-shared=
"true"
>
<provider
class=
"org.eclipse.cdt.managedbuilder.language.settings.providers.GCCBuiltinSpecsDetector"
console=
"false"
env-hash=
"-1
704490246509642878
"
id=
"org.eclipse.cdt.managedbuilder.core.GCCBuiltinSpecsDetector"
keep-relative-paths=
"false"
name=
"CDT GCC Built-in Compiler Settings"
parameter=
"${COMMAND} ${FLAGS} -E -P -v -dD "${INPUTS}""
prefer-non-shared=
"true"
>
<language-scope
id=
"org.eclipse.cdt.core.gcc"
/>
<language-scope
id=
"org.eclipse.cdt.core.g++"
/>
</provider>
...
...
This diff is collapsed.
Click to expand it.
src/PruebaOpenCV.cpp
0 → 100644
+
224
−
0
View file @
4ff0e280
/*
using namespace cv;
using namespace std;
#include <opencv2/opencv.hpp>
#include <iostream>
#include <unistd.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <sys/socket.h>
#define BUFLEN 1048576 //1024*1024 //Max length of buffer
#define MAX_QUEUE 10
#define PORT 8890 //The port on which to listen for incoming data
int pruebaRecibirUDP();
int pruebaRecibirTCP();
int main() {
cout << "!!!Hello World!!!" << endl; // prints !!!Hello World!!!
pruebaRecibirTCP();
return 0;
}
void die(char *s)
{
perror(s);
exit(1);
}
int pruebaRecibirUDP();
int pruebaRecibirTCP();
int pruebaRecibirTCP() {
char buf[BUFLEN];
//primitiva SOCKET
int server_socket = socket(AF_INET, SOCK_STREAM, 0);
//primitiva BIND
struct sockaddr_in server_addr;
socklen_t server_addr_size = sizeof server_addr;
server_addr.sin_family = AF_INET;
server_addr.sin_port = htons(PORT);
server_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
bind(
server_socket,
(struct sockaddr*)&server_addr, server_addr_size
);
cout << "Waiting for connection..." << endl;
//primitiva LISTEN
listen(server_socket, MAX_QUEUE);
//primitiva ACCEPT
struct sockaddr_in client_addr;
socklen_t client_addr_size = sizeof client_addr;
int socket_to_client = accept(
server_socket,
(struct sockaddr *)&client_addr, &client_addr_size
);
char delimiter[] = "Grupo25";
char recibido[BUFLEN];
int fin = 0; // Mantiene el indice de los bytes recibidos.
int received_data_size = 1;
while(received_data_size > 0)
{
//primitiva RECEIVE
int data_size = BUFLEN;
received_data_size = recv(socket_to_client, buf, data_size, 0);
//print details of the client/peer and the data received
//printf("\nReceived packet from %s:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
cout << "Datos recibidos: " << received_data_size << endl;
// 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;
//cout << "fin: " << fin << endl;
int inicio = 0;
int found = -1;
while ((found = findPosDelimiter(recibido, fin+1, delimiter, inicio)) != -1) {
char jpg[found-inicio];
//cout << "encontre delimitador en pos: " << found << endl;
for (int h = 0; h < found-inicio; h++) {
jpg[h] = recibido[inicio+h];
}
cout << "nuevo jpg size: " << sizeof(jpg) << endl;
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(1000/30);
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;
//cout << "nuevo fin: " << fin << endl;
}
}
//primitiva CLOSE
//close(socket_to_client);
close(server_socket);
return 0;
}
int findPosDelimiter(const char *array, int len, char * delimiter, int inicio) {
int i = -1;
int pos = 0;
for (i = inicio; i<len; i++) {
if (sizeof(delimiter)-1 == pos) {
if (array[i] == delimiter[pos]) {
return i - sizeof(delimiter) + 2;
} else {
pos=0;
}
} else {
if (array[i] == delimiter[pos]) {
pos++;
} else {
pos=0;
}
}
}
return -1;
}
int pruebaRecibirUDP(){
struct sockaddr_in si_me, si_other;
int s, slen = sizeof(si_other) , recv_len;
char buf[BUFLEN];
//create a UDP socket
if ((s=socket(AF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1)
{
die("socket");
}
// zero out the structure
memset((char *) &si_me, 0, sizeof(si_me));
si_me.sin_family = AF_INET;
si_me.sin_port = htons(PORT);
si_me.sin_addr.s_addr = htonl(INADDR_ANY);
//bind socket to port
if( bind(s , (struct sockaddr*)&si_me, sizeof(si_me) ) == -1)
{
die("bind");
}
socklen_t server_addr_size = sizeof si_other;
//keep listening for data
while(1)
{
printf("Waiting for data...");
fflush(stdout);
//try to receive some data, this is a blocking call
if ((recv_len = recvfrom(s, buf, BUFLEN, 0, (struct sockaddr *) &si_other, &server_addr_size)) == -1)
{
die("recvfrom()");
}
//print details of the client/peer and the data received
printf("\nReceived packet from %s:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
printf("Tamanio Data: %d\n", sizeof(buf));
namedWindow("cliente", CV_WINDOW_AUTOSIZE);
Mat rawData = Mat(1, sizeof(buf), CV_8UC1, buf);
Mat frame = imdecode(rawData, CV_LOAD_IMAGE_COLOR);
imshow("cliente", frame);
waitKey(1000/30);
//now reply the client with the same data
//if (sendto(s, buf, recv_len, 0, (struct sockaddr*) &si_other, slen) == -1)
//{
// die("sendto()");
//}
}
close(s);
return 0;
}
*/
This diff is collapsed.
Click to expand it.
src/Tarea2-RC-Grupo25-Cliente.cpp
+
6
−
211
View file @
4ff0e280
//============================================================================
// Name : Tarea2-RC-Grupo25-Cliente.cpp
// Author :
// Version :
// Copyright : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================
#include
<iostream>
using
namespace
std
;
#include
<iostream>
#include
<unistd.h>
#include
<stdio.h>
//printf
#include
<string.h>
//memset
#include
<stdlib.h>
//exit(0);
#include
<arpa/inet.h>
#include
<sys/socket.h>
#include
<stdio.h>
#include
<string.h>
#include
<stdlib.h>
#include
<arpa/inet.h>
#include
<sys/socket.h>
#include
<opencv2/opencv.hpp>
using
namespace
cv
;
#define BUFLEN 1048576 //1024*1024 //Max length of buffer
#define MAX_QUEUE 10
#define PORT 8890 //The port on which to listen for incoming data
int
pruebaRecibirUDP
();
int
pruebaRecibirTCP
();
int
main
()
{
cout
<<
"!!!Hello World!!!"
<<
endl
;
// prints !!!Hello World!!!
pruebaRecibirTCP
();
return
0
;
}
void
die
(
char
*
s
)
{
perror
(
s
);
exit
(
1
);
}
/**
* Queda escuchando en el puerto UDP indicado.
*
*/
int
pruebaRecibirUDP
(){
struct
sockaddr_in
si_me
,
si_other
;
int
s
,
slen
=
sizeof
(
si_other
)
,
recv_len
;
char
buf
[
BUFLEN
];
//create a UDP socket
if
((
s
=
socket
(
AF_INET
,
SOCK_DGRAM
,
IPPROTO_UDP
))
==
-
1
)
{
die
(
"socket"
);
}
// zero out the structure
memset
((
char
*
)
&
si_me
,
0
,
sizeof
(
si_me
));
si_me
.
sin_family
=
AF_INET
;
si_me
.
sin_port
=
htons
(
PORT
);
si_me
.
sin_addr
.
s_addr
=
htonl
(
INADDR_ANY
);
//bind socket to port
if
(
bind
(
s
,
(
struct
sockaddr
*
)
&
si_me
,
sizeof
(
si_me
)
)
==
-
1
)
{
die
(
"bind"
);
}
socklen_t
server_addr_size
=
sizeof
si_other
;
//keep listening for data
while
(
1
)
{
printf
(
"Waiting for data..."
);
fflush
(
stdout
);
//try to receive some data, this is a blocking call
if
((
recv_len
=
recvfrom
(
s
,
buf
,
BUFLEN
,
0
,
(
struct
sockaddr
*
)
&
si_other
,
&
server_addr_size
))
==
-
1
)
{
die
(
"recvfrom()"
);
}
//print details of the client/peer and the data received
printf
(
"
\n
Received packet from %s:%d
\n
"
,
inet_ntoa
(
si_other
.
sin_addr
),
ntohs
(
si_other
.
sin_port
));
printf
(
"Tamanio Data: %d
\n
"
,
sizeof
(
buf
));
namedWindow
(
"cliente"
,
CV_WINDOW_AUTOSIZE
);
Mat
rawData
=
Mat
(
1
,
sizeof
(
buf
),
CV_8UC1
,
buf
);
Mat
frame
=
imdecode
(
rawData
,
CV_LOAD_IMAGE_COLOR
);
imshow
(
"cliente"
,
frame
);
waitKey
(
1000
/
30
);
//now reply the client with the same data
/*
if (sendto(s, buf, recv_len, 0, (struct sockaddr*) &si_other, slen) == -1)
{
die("sendto()");
}
*/
}
close
(
s
);
return
0
;
}
int
findPosDelimiter
(
const
char
*
array
,
int
len
,
char
*
delimiter
,
int
inicio
)
{
int
i
=
-
1
;
int
pos
=
0
;
for
(
i
=
inicio
;
i
<
len
;
i
++
)
{
if
(
sizeof
(
delimiter
)
-
1
==
pos
)
{
if
(
array
[
i
]
==
delimiter
[
pos
])
{
return
i
-
sizeof
(
delimiter
)
+
2
;
}
else
{
pos
=
0
;
}
}
else
{
if
(
array
[
i
]
==
delimiter
[
pos
])
{
pos
++
;
}
else
{
pos
=
0
;
}
}
}
return
-
1
;
}
int
pruebaRecibirTCP
()
{
char
buf
[
BUFLEN
];
//primitiva SOCKET
int
server_socket
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
//primitiva BIND
struct
sockaddr_in
server_addr
;
socklen_t
server_addr_size
=
sizeof
server_addr
;
server_addr
.
sin_family
=
AF_INET
;
server_addr
.
sin_port
=
htons
(
PORT
);
server_addr
.
sin_addr
.
s_addr
=
inet_addr
(
"127.0.0.1"
);
bind
(
server_socket
,
(
struct
sockaddr
*
)
&
server_addr
,
server_addr_size
);
cout
<<
"Waiting for connection..."
<<
endl
;
//primitiva LISTEN
listen
(
server_socket
,
MAX_QUEUE
);
//primitiva ACCEPT
struct
sockaddr_in
client_addr
;
socklen_t
client_addr_size
=
sizeof
client_addr
;
int
socket_to_client
=
accept
(
server_socket
,
(
struct
sockaddr
*
)
&
client_addr
,
&
client_addr_size
);
char
delimiter
[]
=
"Grupo25"
;
char
recibido
[
BUFLEN
];
int
fin
=
0
;
// Mantiene el indice de los bytes recibidos.
int
received_data_size
=
1
;
while
(
received_data_size
>
0
)
{
//primitiva RECEIVE
int
data_size
=
BUFLEN
;
received_data_size
=
recv
(
socket_to_client
,
buf
,
data_size
,
0
);
//print details of the client/peer and the data received
//printf("\nReceived packet from %s:%d\n", inet_ntoa(si_other.sin_addr), ntohs(si_other.sin_port));
cout
<<
"Datos recibidos: "
<<
received_data_size
<<
endl
;
// 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
;
//cout << "fin: " << fin << endl;
int
inicio
=
0
;
int
found
=
-
1
;
while
((
found
=
findPosDelimiter
(
recibido
,
fin
+
1
,
delimiter
,
inicio
))
!=
-
1
)
{
char
jpg
[
found
-
inicio
];
//cout << "encontre delimitador en pos: " << found << endl;
for
(
int
h
=
0
;
h
<
found
-
inicio
;
h
++
)
{
jpg
[
h
]
=
recibido
[
inicio
+
h
];
}
cout
<<
"nuevo jpg size: "
<<
sizeof
(
jpg
)
<<
endl
;
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
(
1000
/
30
);
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
;
//cout << "nuevo fin: " << fin << endl;
}
}
//primitiva CLOSE
//close(socket_to_client);
close
(
server_socket
);
return
0
;
}
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