-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathClient4.c
55 lines (40 loc) · 1013 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
48
49
50
51
52
53
54
55
#include<stdio.h>
#include<sys/socket.h>
#include<netinet/in.h>
#include<unistd.h>
#include<arpa/inet.h>
#include<string.h>
#include<time.h>
int main()
{
int csd,nsd,clilen,cport=6000;
char revmsg[100];
int len,check=1;
csd = socket(AF_INET,SOCK_STREAM,0);
if(csd<0)
printf("Can't create\n");
else
printf("Client's socket is created\n");
struct sockaddr_in servaddr;
servaddr.sin_family = AF_INET;
servaddr.sin_addr.s_addr = htonl(INADDR_ANY);
servaddr.sin_port = htons(cport);
nsd = connect(csd,(struct sockaddr*)&servaddr,sizeof(servaddr));
if(nsd<0)
printf("Can''t connect\n");
else
printf("Connected\n");
char sendmsg[100];
while(strcmp(revmsg,"BYE"))
{
fgets(sendmsg,20,stdin);
len = strlen(sendmsg);
sendmsg[len-1]='\0';
send(csd,sendmsg,20,0);
recv(csd,revmsg,20,0);
printf("Server msg: %s\n",revmsg);
}
printf("Chat Terminated\n");
close(csd);
return 0;
}