-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathclient13.c
79 lines (69 loc) · 1.1 KB
/
client13.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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
#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>
int check(int n){
int d=11;
int x=n;
x=x>>3;
int t;
//cout<<x<<" ";
for(int i=2;i>=0;i--){
if((x>>3&1)==0){
x=x<<1;
x|=(n&(1<<i));
//cout<<x<<" ";
continue;
}
t=x^d;
t=t<<1;
t|=(n&(1<<i));
x=t;
//cout<<x<<" ";
}
x=x^d;
return x;
}
int main(){
int sock;
int n;
int c;
unsigned int len;
struct sockaddr_in client;
if( ( sock=socket(AF_INET,SOCK_STREAM,0))==-1 )
{
perror("error");
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("error");
exit(-1);
}
while(1)
{
cin>>n;
n=n<<3;
n^=check(n);
send(sock,&n,sizeof(n),0);
printf("\npress -1 to exit and 0 to continue\n");
scanf("%d",&c);
if(c==-1)
{
close(sock);
exit (0);
break;
}
}
return 0;
}