-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathSend_Structure_for_Authentication_Client
More file actions
50 lines (41 loc) · 926 Bytes
/
Send_Structure_for_Authentication_Client
File metadata and controls
50 lines (41 loc) · 926 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
#include<stdio.h>
#include<stdlib.h>
#include<sys/types.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<string.h>
struct myStruct{
char name[10];
int userId;
char password[10];
};
int main(){
int sockfd;
struct sockaddr_in server;
sockfd = socket(AF_INET, SOCK_STREAM, 0);
if(sockfd==-1){
printf("Socket not created\n");
exit(0);
}else{
printf("Socket Created\n");
}
server.sin_family = AF_INET;
server.sin_port = htons(3050);
server.sin_addr.s_addr = INADDR_ANY;
int x=connect(sockfd, (struct sockaddr *)&server, sizeof(server));
if(x==-1){
printf("Connection Failure\n");
exit(0);
}
struct myStruct myst;
printf("Enter userId : ");
scanf("%d",&myst.userId);
printf("Enter password : ");
scanf("%s",myst.password);
send(sockfd,&myst,sizeof(myst),0);
char message[20];
recv(sockfd, message, sizeof(message), 0);
printf("%s",message);
close(sockfd);
return 0;
}