-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathclient.c
More file actions
56 lines (37 loc) · 1020 Bytes
/
client.c
File metadata and controls
56 lines (37 loc) · 1020 Bytes
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
#include <unistd.h>
#include <stdio.h>
#include <sys/socket.h>
#include <string.h>
#include <stdlib.h>
#include <netinet/in.h>
#include <string.h>
#include <sys/types.h>
#include <netdb.h>
#include <arpa/inet.h>
#define PORT 4444
int main()
{
int sockfd, ret, n;
struct sockaddr_in serverAddr;
char buffer[100];
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd < 0) perror("error in socket\n");
memset(&serverAddr, '\0', sizeof(serverAddr));
serverAddr.sin_family = AF_INET;
serverAddr.sin_port = htons(PORT);
serverAddr.sin_addr.s_addr = inet_addr("127.0.0.1");
ret = connect(sockfd, (struct sockaddr*)&serverAddr, sizeof(serverAddr));
if(ret < 0) perror("error in connect\n");
int requests = 20;
while(requests -- > 0)
{
bzero(buffer, 100);
sprintf(buffer, "%d", requests+1);
n = send(sockfd, &buffer, strlen(buffer), 0);
bzero(buffer, 100);
n = recv(sockfd, &buffer, 100, 0);
printf("Factorial returned by Server : %s\n\n", buffer);
}
close(sockfd);
return 0;
}