-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
61 lines (48 loc) · 1.11 KB
/
client.c
File metadata and controls
61 lines (48 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
/* Protocolos de Internet
* Gabriel Acosta
*
* Creacion de sockets entre servidor-cliente
* 11/09/15
* client.c
*/
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#include <string.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <arpa/inet.h>
#include <stdlib.h>
#include <stdio.h>
int main() {
/* fflush(stdin); */
/* fflush(stdout); */
int client_dtr, i;
struct sockaddr_in client;
int port = 2500;
char buf[30];
char saludo[20];
client_dtr = socket(AF_INET,
SOCK_STREAM, 0);
client.sin_addr.s_addr = inet_addr("127.0.0.1");
client.sin_family = AF_INET;
client.sin_port = htons(port);
connect(client_dtr,
(struct sockaddr *)&client,
sizeof(client));
/* Tal vez se requieran mas de una llamada
a recv para recibir toda la informacion
enviada desde el server*/
recv(client_dtr, saludo, 20, 0);
printf("%s\n", saludo);
fflush(stdin);
fflush(stdout);
fgets(buf, 30, stdin);
write(client_dtr, buf, 30);
int l;
recv(client_dtr, &l, sizeof(l), 0);
printf("Longitud : %i\n", l);
close(client_dtr);
fflush(stdout);
return 0;
}