-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient4.c
47 lines (40 loc) · 963 Bytes
/
client4.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
#include <stdio.h>
#include <stdlib.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <errno.h>
#include <string.h>
#include <arpa/inet.h>
#include <unistd.h>
#include<string.h>
void main(){
int sock;
unsigned int len;
int n,a,b,add,sub,mul,div;
char s[100];
struct sockaddr_in client;
if((sock=socket(AF_INET,SOCK_STREAM,0))==-1){
perror("socket: ");
exit(-1);
}
client.sin_family=AF_INET;
client.sin_port=htons(10000);
client.sin_addr.s_addr=INADDR_ANY;
bzero(&client.sin_zero,0);
len=sizeof(struct sockaddr_in);
if((connect(sock,(struct sockaddr *)&client,len))==-1){
perror("connect: ");
exit(-1);
}
printf("Enter two numbers\n");
scanf("%d%d",&a,&b);
send(sock,&a,sizeof(a),0);
send(sock,&b,sizeof(b),0);
recv(sock,&add,sizeof(add),0);
recv(sock,&mul,sizeof(mul),0);
recv(sock,&sub,sizeof(sub),0);
recv(sock,&div,sizeof(div),0);
printf("%d %d %d %d\n",add,sub,mul,div );
close(sock);
}