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
172cf00a
Commit
172cf00a
authored
7 years ago
by
Ramiro Facundo Lorenzo Rodriguez Inthamoussu
Browse files
Options
Downloads
Patches
Plain Diff
cli
parent
ae1f09d4
No related branches found
No related tags found
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/Tarea2-RC-Grupo25-Cliente.cpp
+67
-3
67 additions, 3 deletions
src/Tarea2-RC-Grupo25-Cliente.cpp
with
67 additions
and
3 deletions
src/Tarea2-RC-Grupo25-Cliente.cpp
+
67
−
3
View file @
172cf00a
...
...
@@ -15,11 +15,37 @@ using namespace std;
#include
<stdlib.h>
#include
<stdio.h>
#define PORT "9999"
#define HOST "localhost"
#define MAXLEN 1024
int
main
()
{
void
error
(
const
char
*
);
void
TCP
(
const
char
*
PORT
,
const
char
*
HOST
);
void
UDP
(
int
PORT
,
const
char
*
HOST
);
int
main
(
int
argc
,
char
*
argv
[])
{
printf
(
"argv[0]: %s
\n
"
,
argv
[
0
]
);
printf
(
"argv[1]: %s
\n
"
,
argv
[
1
]
);
if
(
strcmp
(
argv
[
1
],
"TCP"
)
==
0
){
TCP
(
"9999"
,
argv
[
2
]);
}
else
if
(
strcmp
(
argv
[
1
],
"UDP"
)
==
0
){
UDP
(
9998
,
argv
[
2
]);
}
else
{
printf
(
"ERROR: first argument must be TCP or UDP.
\n
"
);
return
-
1
;
}
}
void
error
(
const
char
*
msg
)
{
perror
(
msg
);
exit
(
0
);
}
void
TCP
(
const
char
*
PORT
,
const
char
*
HOST
){
int
client_socket
=
socket
(
AF_INET
,
SOCK_STREAM
,
0
);
//obtenemos la direccion con getaddrinfo
...
...
@@ -59,8 +85,46 @@ int main() {
freeaddrinfo
(
res
);
}
void
UDP
(
int
PORT
,
const
char
*
HOST
){
int
sock
,
n
;
unsigned
int
length
;
struct
sockaddr_in
server
,
from
;
struct
hostent
*
hp
;
char
buffer
[
256
];
sock
=
socket
(
AF_INET
,
SOCK_DGRAM
,
0
);
if
(
sock
<
0
)
error
(
"socket"
);
server
.
sin_family
=
AF_INET
;
hp
=
gethostbyname
(
HOST
);
if
(
hp
==
0
)
error
(
"Unknown host"
);
bcopy
((
char
*
)
hp
->
h_addr
,
(
char
*
)
&
server
.
sin_addr
,
hp
->
h_length
);
server
.
sin_port
=
htons
(
PORT
);
length
=
sizeof
(
struct
sockaddr_in
);
bzero
(
buffer
,
256
);
sprintf
(
buffer
,
"subscription"
);
if
(
sendto
(
sock
,
buffer
,
strlen
(
buffer
),
0
,(
const
struct
sockaddr
*
)
&
server
,
length
)
<
0
)
error
(
"Error on send first datagram"
);
n
=
recvfrom
(
sock
,
buffer
,
256
,
0
,(
struct
sockaddr
*
)
&
from
,
&
length
);
if
(
n
<
0
)
error
(
"recvfrom"
);
write
(
1
,
"Got an ack: "
,
12
);
write
(
1
,
buffer
,
n
);
close
(
sock
);
}
...
...
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