-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathclientHackademy.c
54 lines (49 loc) · 1.24 KB
/
clientHackademy.c
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
#include "wrapper.h"
#include <stdio.h>
#include <netdb.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <string.h>
#include <sys/socket.h>
#include <sys/types.h>
int main(int argc, char **argv)
{
int sockfd,connfd ,n;
char buff[80];
struct sockaddr_in servaddr;
/* gestione errore */
/*if (argc != 2) {
fprintf(stderr,"usage: %s <IPaddress>\n",argv[0]);
exit(1);
}*/
/* creazione socket */
sockfd = Socket(AF_INET, SOCK_STREAM, 0);
bzero(&servaddr, sizeof(servaddr));
servaddr.sin_family = AF_INET;
servaddr.sin_port = htons(27380);
servaddr.sin_addr.s_addr = inet_addr("127.0.0.1");
/* connessione al server */
Connect(sockfd, &servaddr);
/* lettura del Daytime */
while (1)
{
// bzero(buff, sizeof(buff));
memset(buff, 0, sizeof(buff));
printf("Enter the string : ");
n = 0;
while((buff[n++] = getchar()) != '\n');
// printf("%s\n", buff);
FullWrite(sockfd, buff, sizeof(buff));
// bzero(buff, sizeof(buff));
memset(buff, 0, sizeof(buff));
FullRead(sockfd, buff, sizeof(buff));
printf("From Server : %s", buff);
if ((strncmp(buff, "exit", 4)) == 0)
{
printf("Client Exit...\n");
break;
}
}
// close the socket
close(sockfd);
}