-
Notifications
You must be signed in to change notification settings - Fork 1
/
utimeclient.c
39 lines (39 loc) · 883 Bytes
/
utimeclient.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
#include <stdio.h>
#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <stdlib.h>
#include <arpa/inet.h>
#include <unistd.h>
#include <string.h>
int main()
{
int sockfd;
struct sockaddr_in serv_addr;
char a[50],a1[50];
sockfd=socket(AF_INET,SOCK_STREAM,0);
if(sockfd<0)
{
printf("socket failed\n");
exit(0);
}
serv_addr.sin_family=AF_INET;
serv_addr.sin_addr.s_addr = inet_addr("127.0.0.1");
//Change address to server's IPv4 address, dont change if on same machine
serv_addr.sin_port=htons(3100);
if(connect(sockfd,(struct sockaddr *)&serv_addr,sizeof(serv_addr))<0)
{
printf("Connection failed\n");
exit(0);
}
memset(a, 0, sizeof(a));
//printf("Press enter to get time\n");
//scanf("%s",a);
write(sockfd,a,50);
read(sockfd,a1,50);
printf("Client Received %s\n",a1);
close(sockfd);
if(!strcmp(a1,"exit"))
printf("Closing client program\n");
return 0;
}